File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
CircuitPython_Essentials/CircuitPython_I2C_Scan
CircuitPython_Templates/i2c_scan Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 1
- """CircuitPython Essentials I2C Scan example """
1
+ """CircuitPython I2C Device Address Scan """
2
2
# If you run this and it seems to hang, try manually unlocking
3
3
# your I2C bus from the REPL with
4
4
# >>> import board
7
7
import time
8
8
import board
9
9
10
+ # To use default I2C bus (most boards)
10
11
i2c = board .I2C ()
11
12
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
+
12
18
while not i2c .try_lock ():
13
19
pass
14
20
15
21
try :
16
22
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
+ )
19
27
time .sleep (2 )
20
28
21
29
finally : # unlock the i2c bus when ctrl-c'ing out of the loop
Original file line number Diff line number Diff line change 2
2
import time
3
3
import board
4
4
5
+ # To use default I2C bus (most boards)
5
6
i2c = board .I2C ()
6
7
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
+
7
13
while not i2c .try_lock ():
8
14
pass
9
15
10
16
try :
11
17
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
+ )
13
22
time .sleep (2 )
14
23
15
24
finally : # unlock the i2c bus when ctrl-c'ing out of the loop
You can’t perform that action at this time.
0 commit comments