""" MicroPython I2C scanner
Retorna l'adreça (en decimal i hexa) de tots els dispositius connectats al le bus i2c
https://gist.github.com/projetsdiy/f4330be62589ab9b3da1a4eacc6b6b1c """
import machine
i2c = machine.I2C(0, scl=machine.Pin(22), sda=machine.Pin(21)) # pins I2C de l'ESP32
print ('Scan i2c bus...')
devices = i2c.scan()
if len(devices) == 0: # lens() retorna el nombre d'elements d'un objecte
print("No i2c device !")
else:
print('i2c devices found:',len(devices))
for device in devices:
print("Decimal address: ",device," | Hexa address: ",hex(device))
print()