🛠 Controlling GPIO and sensors with UEXT-CH390
Objectives
This tutorial aims to understand how to interact with external peripherals (LEDs, buttons, sensors) connected via the UEXT interface, while utilizing the Ethernet functionality of the CH390 module. We will configure a GPIO to light an LED and read the state of a button, illustrating the coexistence between local resources (GPIO) and network resources (SPI/Ethernet). The goal is to show that the CH390 module, although a network controller, integrates into a system where microcontrollers manage local I/O independently of the SPI bus dedicated to network communication.
Required Hardware
- Compatible development board (e.g., Raspberry Pi Pico or ESP32)
- Olimex UEXT-CH390 module
- UEXT cable (10 pins)
- Breadboard and jumper wires
- One LED and a resistor (220-330 Ω)
- One push button
- USB power supply
Steps
- Hardware Connection: Insert the UEXT-CH390 module into the UEXT connector of your host board. Ensure the power supply is 3.3V. The module uses SPI pins for network communication, leaving other GPIOs free for your projects.
- Software Configuration: In your environment (Arduino IDE or MicroPython), first initialize the Ethernet library for the CH390. Then, configure the local GPIOs. For example, define pin GPIO 15 as output for the LED and GPIO 16 as input for the button.
- Main Loop: In the
loop(), check the button state. If the button is pressed, set the LED toHIGH. Otherwise, set it toLOW. This local logic does not depend on the network connection. - Network Integration (Optional): To demonstrate integration, add a variable that counts button presses. Display this counter on a local web page hosted by the CH390 via a simple HTTP request, showing that local data can be exposed on the network.
Verification
Observe the LED: it should light up only when the button is pressed. If you implemented the network part, open a web browser and navigate to the IP address assigned by DHCP to the CH390 module. You should see the web page updating with the number of button presses. If the LED does not light up, check the soldering and LED polarity. If the web page does not load, check that the Ethernet cable is properly connected and that DHCP was successful.
Going Further
Explore the use of analog inputs (ADC) to read a potentiometer connected via UEXT, and send this value over the network. You can also explore GPIO interrupts to react more quickly to button state changes without polling the pin continuously, thus optimizing microcontroller resources.
Other tutorials for this board
- First connection and startup of the UEXT-CH390
- Complete Use Case: Ethernet Connectivity for Raspberry Pi Pico
- First connection and startup of the UEXT-CH390
- Integrating GPIO with UEXT-CH390 Ethernet
- Connect a RP2040 to the network with UEXT-CH390 and ESPHome
- Advanced Startup: UEXT-CH390 and Raspberry Pi Pico
Code examples for this board
esp32-ch390-lwip-station.inoC++rp2040-pico-ch390-micropython.pyPythonesp32-ch390-udp-sensor-gateway.inoC++esp32-ch390-web-server-local.inoC++rp2040-ch390-iot-home-assistant.inoYAMLrp2040-lwip-ethernet-ping-6.inoC/C++ (Raspberry Pi Pico SDK)