MicroPython I2C Scanner

MicroPython I2C Scanner, tested on Raspberry Pi Pico running CircuitPython v1.19.1.

mpy_i2c_scanner.py
import machine
import os

print(os.uname())
print()
# How many hardware I2C supported
# and show the I2C info
print("number of I2C supported:")
print("========================")
i=0
while True:
    try:
        print(machine.I2C(i))
    except ValueError as e:
        print(e)
        break
    i += 1
print()

#Using machine.SoftI2C
#scl = machine.Pin(9, mode=machine.Pin.OUT, pull=machine.Pin.PULL_UP)
#sda = machine.Pin(8, mode=machine.Pin.OUT, pull=machine.Pin.PULL_UP)
#i2c = machine.SoftI2C(scl, sda)

#Using machine.I2C
i2c = machine.I2C(0)
print(i2c)
print()

print('=== I2C Scanner ===')
devices = i2c.scan()

if len(devices) == 0:
    print("No I2C device found!")
else:
    print('I2C devices found:',len(devices))
    for device in devices:
        print(device, ":", hex(device))



Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

my dev.tools - FNIRSI 2C23T 3-in-1 Dual Channel Oscilloscope/Multimeter/Signal Generator