Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Micropython i2c scanner
# Scanner i2c en MicroPython | MicroPython i2c scanner
# Renvoi l'adresse en decimal et hexa de chaque device connecte sur le bus i2c
# Return decimal and hexa adress of each i2c device
# - (dec. 2017)
import machine
i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
print('Scan i2c bus...')
devices = i2c.scan()
if len(devices) == 0:
print("No i2c device !")
print('i2c devices found:',len(devices))
for device in devices:
print("Decimal address: ",device," | Hexa address: ",hex(device))
Copy link

425629 commented May 11, 2020

Very valuable means to show the first steps in setting up and accessing i2C resources. Other "1st steps" tutorials assumed Pin objects and abstractions that I hadn't learned yet. This gave the starter everything needed.

Copy link

aofek commented Jun 4, 2021

Nice, Thanks

Copy link

urish commented Apr 13, 2022

Wokwi simulation of this code (with two connected I2C devices):


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment