🛠 Advanced GPIO I/O Management with UEXT-CH390

Olimex UEXT-CH390: SPI to Ethernet 10/100 Mbps Module for Microcontrollers · avance · Intégrer des périphériques physiques (capteurs ou afficheurs) dans un système Ethernet filaire basé sur le module UEXT-CH390.

Objectives

This tutorial aims to master the interfacing of physical peripherals (GPIO) with the UEXT-CH390 module to create a complete IoT node. Unlike wireless solutions, wired Ethernet offers predictable latency and superior stability, ideal for industrial control or critical home automation systems. We will configure the host microcontroller's GPIO pins to read an analog or digital sensor and drive a display, while transmitting this data via the CH390 network stack. The focus is on interrupt handling and synchronization between real-time tasks (GPIO) and network tasks (TCP/IP), using the specific RP2040 driver or the ESP-IDF SDK.

Required Hardware

Steps

  1. Physical Connection: Plug the UEXT-CH390 module into the host board's UEXT port. Ensure SPI pins (MOSI, MISO, CLK, CS) are correctly mapped. For the Pico, use default pins GP2-GP5 if not configured otherwise. Note that the module operates in SPI mode 0 or 3.
  1. Network Configuration: In your code (ESPHome or C++), initialize the CH390 driver. Enable DHCP to obtain an IP address. Verify that the factory MAC address is recognized.
  1. GPIO Initialization: Configure your sensor pins as inputs (with pull-up/down if necessary) and display pins as outputs. For an analog sensor, enable the corresponding ADC.
  1. Logic Implementation: Create a periodic task (e.g., every second) that reads the sensor value. Apply a digital filter (moving average) to reduce noise.
  1. Network Transmission: Format the read data into JSON or MQTT protocol. Use the CH390 driver's network APIs to send packets. Ensure GPIO operations do not block the network stack; use interrupts or dedicated RTOS tasks if necessary.
  1. Local Control: Add logic to actuate the display or LED based on detected critical thresholds, ensuring local reaction even if the network is down.

Verification

Connect the board to the network via an RJ45 cable. Open a local web interface or MQTT terminal to observe data reception. Verify connection stability by briefly unplugging/replugging the Ethernet cable to test automatic reconnection. Ensure sensor values change in real-time on the remote interface.

Further Reading

Explore integration with Home Assistant via automatic discovery. Optimize power consumption by sleeping inactive GPIOs. Test network robustness by injecting electromagnetic disturbances, leveraging the better immunity of wired Ethernet compared to Wi-Fi.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials