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 22import time
33import board
44
5+ # To use default I2C bus (most boards)
56i2c = board .I2C ()
67
8+ # To create I2C bus on specific pins
9+ # import busio
10+ # i2c = busio.I2C(board.SCL1, board.SDA1) # QT Py RP2040 STEMMA connector
11+ # i2c = busio.I2C(board.GP1, board.GP0) # Pi Pico RP2040
12+
713while not i2c .try_lock ():
814 pass
915
1016try :
1117 while True :
12- print ("I2C addresses found:" , [hex (device_address ) for device_address in i2c .scan ()])
18+ print (
19+ "I2C addresses found:" ,
20+ [hex (device_address ) for device_address in i2c .scan ()],
21+ )
1322 time .sleep (2 )
1423
1524finally : # unlock the i2c bus when ctrl-c'ing out of the loop
You can’t perform that action at this time.
0 commit comments