We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3e22877 + 0042317 commit 92119d5Copy full SHA for 92119d5
CircuitPython_Essentials/CircuitPython_I2C_Scan.py
@@ -1,15 +1,23 @@
1
# CircuitPython demo - I2C scan
2
+#
3
+# If you run this and it seems to hang, try manually unlocking
4
+# your I2C bus from the REPL with
5
+# >>> import board
6
+# >>> board.I2C().unlock()
7
8
import time
-
9
import board
10
11
i2c = board.I2C()
12
13
while not i2c.try_lock():
14
pass
15
-while True:
- print("I2C addresses found:", [hex(device_address)
- for device_address in i2c.scan()])
- time.sleep(2)
16
+try:
17
+ while True:
18
+ print("I2C addresses found:", [hex(device_address)
19
+ for device_address in i2c.scan()])
20
+ time.sleep(2)
21
+
22
+finally: # unlock the i2c bus when ctrl-c'ing out of the loop
23
+ i2c.unlock()
0 commit comments