i2c-scan.py
Scans the given I2C pins for responsive device(s) and returns their respective addresses.
⚙ Hardware Needed
- PyCubed mainboard
📚 External Libraries Needed
None
📑 Code
import time
import board
import busio
i2c = busio.I2C(board.SCL, board.SDA)
while not i2c.try_lock():
pass
while True:
print("I2C addresses found:", [hex(device_add) for device_add in i2c.scan()])
time.sleep(2)
Using the ⭐pycubed.py helper library:
from pycubed import cubesat
import time
while not cubesat.i2c1.try_lock():
pass
while True:
print("I2C addresses found:", [hex(device_add) for device_add in cubesat.i2c1.scan()])
time.sleep(2)