Skip to content

Commit 0b4ebde

Browse files
committed
add code for busio setup
1 parent d94fb1e commit 0b4ebde

File tree

2 files changed

+26
-4
lines changed
  • CircuitPython_Essentials/CircuitPython_I2C_Scan
  • CircuitPython_Templates/i2c_scan

2 files changed

+26
-4
lines changed

CircuitPython_Essentials/CircuitPython_I2C_Scan/code.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
@@ -7,15 +7,23 @@
77
import time
88
import board
99

10+
# To use default I2C bus (most boards)
1011
i2c = 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+
1218
while not i2c.try_lock():
1319
pass
1420

1521
try:
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

2129
finally: # unlock the i2c bus when ctrl-c'ing out of the loop

CircuitPython_Templates/i2c_scan/code.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
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+
27
import time
38
import board
49

10+
# To use default I2C bus (most boards)
511
i2c = 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+
718
while not i2c.try_lock():
819
pass
920

1021
try:
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

1529
finally: # unlock the i2c bus when ctrl-c'ing out of the loop

0 commit comments

Comments
 (0)