Sample I2C – Device Scan - renesas/micropython GitHub Wiki

-
Scan I2C bus and list connected devices.
-
Example for RA4M1 Clicker: Connect scl(P205), sda(P206), VCC and GND
import machine
i2c = machine.I2C(scl=machine.Pin.cpu.P205, sda=machine.Pin.cpu.P206)
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))

- Example for EK-RA6M2: Connect scl(P100), sda(P206), VCC and GND
import machine
i2c = machine.I2C(scl=machine.Pin.cpu.P205, sda=machine.Pin.cpu.P206)
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))

- Other pin can be used because this feature is supported by software I2C.