Skip to content

Instantly share code, notes, and snippets.

@helgibbons
Created February 13, 2023 15:08
Show Gist options
  • Select an option

  • Save helgibbons/5b0cba438ae68f100f252a6cef063773 to your computer and use it in GitHub Desktop.

Select an option

Save helgibbons/5b0cba438ae68f100f252a6cef063773 to your computer and use it in GitHub Desktop.
Scan for I2C devices on Pico
import machine
sda=machine.Pin(4)
scl=machine.Pin(5)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
print('Scan i2c bus...')
devices = i2c.scan()
if len(devices) == 0:
print("No i2c device !")
else:
print('i2c devices found:',len(devices))
for device in devices:
print("Decimal address: ",device," | Hexa address: ",hex(device))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment