Wrapper library for debugging I2C.

  • Author(s): Roy Hooper, Kattni Rembor

Implementation Notes

Software and Dependencies:

class adafruit_debug_i2c.DebugI2C(i2c: I2C)

Wrapper library for debugging I2C.

This library wraps an I2C object and prints buffers before writes and after reads.

See the I2C documentation for detailed documentation on the methods in this class.


i2c – An initialized I2C object to debug.

This example uses the LIS3DH accelerometer. This lib can be used with any I2C device. Save the code to your board.

import adafruit_lis3dh
from adafruit_debug_i2c import DebugI2C
import busio
import board
import digitalio

i2c = DebugI2C(busio.I2C(board.SCL, board.SDA))
int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
accelerometer = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1)


for i in range(2):
deinit() None

Releases control of the underlying I2C hardware so other classes can use it.

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

Debug version of readfrom_into that prints the buffer after reading.

  • address (int) – 7-bit device address

  • buffer (~WritableBuffer) – buffer to write into

  • start (int) – Index to start writing at

  • end (int) – Index to write up to but not include

scan() List[int]

Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of those that respond.


List of device ids on the I2C bus

Return type:


try_lock() bool

Attempts to grab the I2C lock. Returns True on success.


True when lock has been grabbed

Return type:


unlock() None

Releases the I2C lock.

writeto(address: int, buffer: array | bytearray | bytes | memoryview | rgbmatrix.RGBMatrix | ulab.numpy.ndarray, *args, **kwargs) None

Debug version of write that prints the buffer before sending.

  • address (int) – 7-bit device address

  • buffer (~ReadableBuffer) – buffer containing the bytes to write

  • start (int) – Index to start writing from

  • end (int) – Index to read up to but not include

  • stop (bool) – If true, output an I2C stop condition after the buffer is written