<reponame>Yarik9008/SoftAcademic<filename>unit-test/circuitpython/test-i2c.py<gh_stars>0
"""CircuitPython I2C Device Address Scan"""
# If you run this and it seems to hang, try manually unlocking
# your I2C bus from the REPL with
#  >>> import board
#  >>> board.I2C().unlock()

import time
import board
import busio


i2c = busio.I2C(board.GP3, board.GP2)
# To create I2C bus on specific pins
# import busio
# i2c = busio.I2C(board.SCL1, board.SDA1)  # QT Py RP2040 STEMMA connector
#i2c = busio.I2C(board.GP1, board.GP0)    # Pi Pico RP2040

while not i2c.try_lock():
    pass

try:
    while True:
        print("I2C addresses found:",[hex(device_address) for device_address in i2c.scan()])
        time.sleep(0.1)

finally:  # unlock the i2c bus when ctrl-c'ing out of the loop
    i2c.unlock()

"""CircuitPython I2C Device Address Scan"""
# If you run this and it seems to hang, try manually unlocking
# your I2C bus from the REPL with
#  >>> import board
#  >>> board.I2C().unlock()

import time
import board
import busio


i2c = busio.I2C(board.GP3, board.GP2)
# To create I2C bus on specific pins
# import busio
# i2c = busio.I2C(board.SCL1, board.SDA1)  # QT Py RP2040 STEMMA connector
#i2c = busio.I2C(board.GP1, board.GP0)    # Pi Pico RP2040

while not i2c.try_lock():
    pass

try:
    while True:
        print("I2C addresses found:",[hex(device_address) for device_address in i2c.scan()])
        time.sleep(0.1)

finally:  # unlock the i2c bus when ctrl-c'ing out of the loop
    i2c.unlock()
CircuitPython I2C Device Address Scan # If you run this and it seems to hang, try manually unlocking # your I2C bus from the REPL with #  >>> import board #  >>> board.I2C().unlock() # To create I2C bus on specific pins # import busio # i2c = busio.I2C(board.SCL1, board.SDA1)  # QT Py RP2040 STEMMA connector #i2c = busio.I2C(board.GP1, board.GP0)    # Pi Pico RP2040 # unlock the i2c bus when ctrl-c'ing out of the loop