adafruit_bitbangio

A library for adding bitbang I2C and SPI to CircuitPython without the built-in bitbangio module. The interface is intended to be the same as bitbangio and therefore there is no bit order or chip select functionality. If your board supports bitbangio, it is recommended to use that instead as the timing should be more reliable.

  • Author(s): Melissa LeBlanc-Williams

Implementation Notes

Software and Dependencies:

class adafruit_bitbangio.I2C(scl: Pin, sda: Pin, *, frequency: int = 400000, timeout: float = 1)

Software-based implementation of the I2C protocol over GPIO pins.

deinit() None

Free any hardware used by the object.

readfrom_into(address: int, buffer: array | bytearray | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray, *, start: int = 0, end: int | None = None) None

Read data from an address and into the buffer

scan() List[int]

Perform an I2C Device Scan

writeto(address: int, buffer: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray, *, start: int = 0, end: int | None = None) None

Write data from the buffer to an address

writeto_then_readfrom(address: int, buffer_out: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray, buffer_in: array | bytearray | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray, *, out_start: int = 0, out_end: int | None = None, in_start: int = 0, in_end: int | None = None) None

Write data from buffer_out to an address and then read data from an address and into buffer_in

class adafruit_bitbangio.SPI(clock: Pin, MOSI: Pin | None = None, MISO: Pin | None = None)

Software-based implementation of the SPI protocol over GPIO pins.

configure(*, baudrate: int = 100000, polarity: Literal[0, 1] = 0, phase: Literal[0, 1] = 0, bits: int = 8) None

Configures the SPI bus. Only valid when locked.

deinit() None

Free any hardware used by the object.

property frequency: int

Return the currently configured baud rate

readinto(buffer: array | bytearray | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray, start: int = 0, end: int | None = None, write_value: int = 0) None

Read into the buffer specified by buf while writing zeroes. Requires the SPI being locked. If the number of bytes to read is 0, nothing happens.

write(buffer: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray, start: int = 0, end: int | None = None) None

Write the data contained in buf. Requires the SPI being locked. If the buffer is empty, nothing happens.

write_readinto(buffer_out: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray, buffer_in: array | bytearray | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray, *, out_start: int = 0, out_end: int | None = None, in_start: int = 0, in_end: int | None = None) None

Write out the data in buffer_out while simultaneously reading data into buffer_in. The lengths of the slices defined by buffer_out[out_start:out_end] and buffer_in[in_start:in_end] must be equal. If buffer slice lengths are both 0, nothing happens.