adafruit_bus_device.spi_device – SPI Device Manager

class adafruit_bus_device.spi_device.SPIDevice(spi: busio.SPI, chip_select: digitalio.DigitalInOut, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, extra_clocks: int = 0)

Represents a single SPI device and manages locking the bus and the device address.

  • spi (SPI) – The SPI bus the device is on

  • chip_select (DigitalInOut) – The chip select pin object that implements the DigitalInOut API.

  • cs_active_value (bool) – Set to true if your device requires CS to be active high. Defaults to false.

  • extra_clocks (int) – The minimum number of clock cycles to cycle the bus after CS is high. (Used for SD cards.)


import busio
import digitalio
from board import *
from adafruit_bus_device.spi_device import SPIDevice
with busio.SPI(SCK, MOSI, MISO) as spi_bus:
    cs = digitalio.DigitalInOut(D10)
    device = SPIDevice(spi_bus, cs)
    bytes_read = bytearray(4)
    # The object assigned to spi in the with statements below
    # is the original spi_bus object. We are using the busio.SPI
    # operations busio.SPI.readinto() and busio.SPI.write().
    with device as spi:
    # A second transaction
    with device as spi:
__enter__() busio.SPI

Starts a SPI transaction by configuring the SPI and asserting chip select.

__exit__() None

Ends a SPI transaction by deasserting chip select. See Lifetime and ContextManagers for more info.