31 lines
745 B
Python
31 lines
745 B
Python
from machine import Pin, I2C
|
|
import time
|
|
|
|
# Scan I2C0 on GP0=SDA, GP1=SCL
|
|
i2c0 = I2C(0, scl=Pin(1), sda=Pin(0), freq=400000)
|
|
|
|
# Scan I2C1 on GP2=SDA, GP3=SCL
|
|
i2c1 = I2C(1, scl=Pin(3), sda=Pin(2), freq=400000)
|
|
|
|
while True:
|
|
print("Scanning I2C buses...")
|
|
devices0 = i2c0.scan()
|
|
devices1 = i2c1.scan()
|
|
|
|
if devices0:
|
|
print("I2C0 Devices found:")
|
|
for d in devices0:
|
|
print(" - Address: 0x{:02X}".format(d))
|
|
else:
|
|
print("No devices found on I2C0")
|
|
|
|
if devices1:
|
|
print("I2C1 Devices found:")
|
|
for d in devices1:
|
|
print(" - Address: 0x{:02X}".format(d))
|
|
else:
|
|
print("No devices found on I2C1")
|
|
|
|
print("-----------------------------")
|
|
time.sleep(3)
|