🛠 Controlling GPIO and sensors with UEXT-CH390

Olimex UEXT-CH390: SPI to Ethernet 10/100 Mbps Module for Microcontrollers · debutant · Apprenez à gérer les entrées/sorties numériques et analogiques via le bus UEXT tout en maintenant la connectivité Ethernet.

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

Steps

  1. 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.
  2. 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.
  3. Main Loop: In the loop(), check the button state. If the button is pressed, set the LED to HIGH. Otherwise, set it to LOW. This local logic does not depend on the network connection.
  4. 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

Code examples for this board

← Back to the board 🛠 All tutorials