File tree Expand file tree Collapse file tree
CircuitPython_Essentials/CircuitPython_I2C_Scan
CircuitPython_Templates/i2c_scan Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- """CircuitPython Essentials I2C Scan example """
1+ """CircuitPython I2C Device Address Scan """
22# If you run this and it seems to hang, try manually unlocking
33# your I2C bus from the REPL with
44# >>> import board
77import time
88import board
99
10+ # To use default I2C bus (most boards)
1011i2c = board .I2C ()
1112
13+ # To create I2C bus on specific pins
14+ # import busio
15+ # i2c = busio.I2C(board.SCL1, board.SDA1) # QT Py RP2040 STEMMA connector
16+ # i2c = busio.I2C(board.GP1, board.GP0) # Pi Pico RP2040
17+
1218while not i2c .try_lock ():
1319 pass
1420
1521try :
1622 while True :
17- print ("I2C addresses found:" , [hex (device_address )
18- for device_address in i2c .scan ()])
23+ print (
24+ "I2C addresses found:" ,
25+ [hex (device_address ) for device_address in i2c .scan ()],
26+ )
1927 time .sleep (2 )
2028
2129finally : # unlock the i2c bus when ctrl-c'ing out of the loop
Original file line number Diff line number Diff line change 11"""CircuitPython I2C Device Address Scan"""
2+ # If you run this and it seems to hang, try manually unlocking
3+ # your I2C bus from the REPL with
4+ # >>> import board
5+ # >>> board.I2C().unlock()
6+
27import time
38import board
49
10+ # To use default I2C bus (most boards)
511i2c = board .I2C ()
612
13+ # To create I2C bus on specific pins
14+ # import busio
15+ # i2c = busio.I2C(board.SCL1, board.SDA1) # QT Py RP2040 STEMMA connector
16+ # i2c = busio.I2C(board.GP1, board.GP0) # Pi Pico RP2040
17+
718while not i2c .try_lock ():
819 pass
920
1021try :
1122 while True :
12- print ("I2C addresses found:" , [hex (device_address ) for device_address in i2c .scan ()])
23+ print (
24+ "I2C addresses found:" ,
25+ [hex (device_address ) for device_address in i2c .scan ()],
26+ )
1327 time .sleep (2 )
1428
1529finally : # unlock the i2c bus when ctrl-c'ing out of the loop
You can’t perform that action at this time.
0 commit comments