The program scans the addresses of devices connected via I²C.
Important: The Ethernet module is accessible by RP2040_ETH via UART1 with the following configuration:
uart1 = UART(1, baudrate=115200, tx=Pin(20), rx=Pin(21), timeout=50)
import machine from machine import Pin, I2C import time # I2C configuration for RP2040-ETH # Using I2C port 0, SDA on Pin 4, SCL on Pin 5, at 100kHz frequency i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=100000) def scan_i2c(): print("I2C Scanner starting...") print("Scanning bus I2C0 (SDA=GP4, SCL=GP5)...") # scan() returns a list of 7-bit decimal addresses of found devices devices = i2c.scan() if not devices: print("No I2C devices found. Check your wiring and pull-up resistors.") else: print(f"Found {len(devices)} device(s):") for device in devices: # Print the address in both decimal and hexadecimal format print(f" - Decimal: {device}, Hex: {hex(device)}") # Run the scanner if __name__ == "__main__": while True: scan_i2c() # Wait 5 seconds before the next scan time.sleep(5)
Output example:
I2C Scanner starting... Scanning bus I2C0 (SDA=GP4, SCL=GP5)... Found 2 device(s): - Decimal: 90, Hex: 0x5a - Decimal: 119, Hex: 0x77
This page has been accessed for: Today: 6, Until now: 13