CircuitPython to scan I2C devices address

To scan I2C devices address using CircuitPython:

import time
import board

print("I2C SDA:", board.SDA)
print("I2C SCL:", board.SCL)
i2c = board.I2C()

while not i2c.try_lock():
    pass

try:
    devices = i2c.scan()
    print("I2C addresses:",
          [hex(address) for address in devices])

finally:
    i2c.unlock()


Test on Seeed Studio XIAO nRF52840 Sense with XIAO Expansion board, running CircuitPython 7.3.2.


Comments