Ted Juan
Published

How to use I2C Pins in Raspberry Pi Pico | I2C Scanner Code

In this tutorial, we will learn how to use I2C Pins in Raspberry Pi Pico & go through the I2C Scanner Code.

IntermediateProtip2 hours58,766
How to use I2C Pins in Raspberry Pi Pico | I2C Scanner Code

Things used in this project

Story

Read more

Code

Code snippet #1

Plain text
import machine
sda=machine.Pin(8)
scl=machine.Pin(9)
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))

Credits

Mr. Alam

Posted by Ted Juan
Thanks to Mr. Alam.

Comments