Created
February 13, 2023 15:08
-
-
Save helgibbons/5b0cba438ae68f100f252a6cef063773 to your computer and use it in GitHub Desktop.
Scan for I2C devices on Pico
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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