Scans the given I2C pins for responsive device(s) and returns their respective addresses.

⚙ Hardware Needed


📚 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)

↩ Return Home

↩ Return to Resources

↩ Return to Code Examples