adafruit_debug_i2c

Wrapper library for debugging I2C.

  • Author(s): Roy Hooper, Kattni Rembor

Implementation Notes

Software and Dependencies:

class adafruit_debug_i2c.DebugI2C(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.

Parameters: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)

print(accelerometer.acceleration)

for i in range(2):
    print(accelerometer.acceleration)
deinit()

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

readfrom_into(address, buffer, *args, start=0, end=None)

Debug version of readfrom_into that prints the buffer after reading.

Parameters:
  • address (int) – 7-bit device address
  • buffer (bytearray) – buffer to write into
  • start (int) – Index to start writing at
  • end (int) – Index to write up to but not include
scan()

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

Returns:List of device ids on the I2C bus
Return type:list
try_lock()

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

Returns:True when lock has been grabbed
Return type:bool
unlock()

Releases the I2C lock.

writeto(address, buffer, *args, **kwargs)

Debug version of write that prints the buffer before sending.

Parameters:
  • address (int) – 7-bit device address
  • buffer (bytearray) – 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