code.py
1 # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 # SPDX-License-Identifier: MIT 3 """CircuitPython I2C Device Address Scan""" 4 import time 5 import board 6 7 # To use default I2C bus (most boards) 8 i2c = board.I2C() 9 10 # To use the STEMMA QT connector (most boards) 11 # i2c = board.STEMMA_I2C() 12 13 # To create I2C bus on specific pins 14 # import busio 15 # i2c = busio.I2C(board.GP1, board.GP0) # Pi Pico RP2040 16 17 while not i2c.try_lock(): 18 pass 19 20 try: 21 while True: 22 print( 23 "I2C addresses found:", 24 [hex(device_address) for device_address in i2c.scan()], 25 ) 26 time.sleep(2) 27 28 finally: # unlock the i2c bus when ctrl-c'ing out of the loop 29 i2c.unlock()