rp2040-pico-ch390-micropython.py

Olimex UEXT-CH390: SPI to Ethernet 10/100 Mbps Module for Microcontrollers · File : rp2040-pico-ch390-micropython.py · Language : Python · Use case : Configurer une connexion Ethernet filaire sur Raspberry Pi Pico avec MicroPython et le module CH390.

Using the MicroPython network API to enable DHCP on the CH390 controller connected via SPI.

Use a MicroPython version for RP2040 with the CH390 driver included (often available via community builds or Olimex). Connect the module to SPI1 pins. The code displays the DHCP-obtained IP address every 5 seconds.

rp2040-pico-ch390-micropython.py

import network
import time

# Configuration SPI pour Olimex UEXT-CH390 sur RP2040
# Pins physiques UEXT: MOSI=GP11, MISO=GP12, CLK=GP10, CS=GP13
spi = network.SPI(1, baudrate=20000000, polarity=0, phase=0, sck=10, mosi=11, miso=12)

# Initialisation de l'interface Ethernet CH390
# Note: Nécessite le firmware MicroPython compilé avec le support CH390
eth = network.CH390(spi, cs=13)

# Configuration DHCP
eth.ifconfig("dhcp")

# Boucle principale pour vérifier la connexion
while True:
    if eth.active():
        ip_info = eth.ifconfig()
        print(f"Connected. IP: {ip_info[0]}, Mask: {ip_info[1]}, GW: {ip_info[2]}")
    else:
        print("Waiting for link...")
    time.sleep(5)

← Back to the board