code.py
1 # SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """CircuitPython I2C Device Address Scan""" 6 # If you run this and it seems to hang, try manually unlocking 7 # your I2C bus from the REPL with 8 # >>> import board 9 # >>> board.I2C().unlock() 10 11 import time 12 import board 13 14 # To use default I2C bus (most boards) 15 i2c = board.I2C() 16 17 # To create I2C bus on specific pins 18 # import busio 19 # i2c = busio.I2C(board.SCL1, board.SDA1) # QT Py RP2040 STEMMA connector 20 # i2c = busio.I2C(board.GP1, board.GP0) # Pi Pico RP2040 21 22 while not i2c.try_lock(): 23 pass 24 25 try: 26 while True: 27 print( 28 "I2C addresses found:", 29 [hex(device_address) for device_address in i2c.scan()], 30 ) 31 time.sleep(2) 32 33 finally: # unlock the i2c bus when ctrl-c'ing out of the loop 34 i2c.unlock()