Skip to content

Commit 59ae4b1

Browse files
authored
Merge pull request #2330 from kattni/i2c-scan-code
Add PiCowbell CircuitPython I2C scan.
2 parents e194e43 + e498983 commit 59ae4b1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

PiCowbell_Proto/i2c_scan/code.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""CircuitPython I2C Device Address Scan for PiCowbell Proto and Pico"""
4+
import time
5+
import board
6+
7+
i2c = board.STEMMA_I2C()
8+
9+
while not i2c.try_lock():
10+
pass
11+
12+
try:
13+
while True:
14+
print(
15+
"I2C addresses found:",
16+
[hex(device_address) for device_address in i2c.scan()],
17+
)
18+
time.sleep(2)
19+
20+
finally: # unlock the i2c bus when ctrl-c'ing out of the loop
21+
i2c.unlock()

0 commit comments

Comments
 (0)