🛠 Driving GPIO and LCD on ToughC5
Objectives
This tutorial aims to master physical interaction with the M5Stack ToughC5 kit. You will learn to configure GPIO pins for digital input reading and drive the 2.0-inch capacitive touch ILI9342C LCD. The goal is to create a basic interface displaying sensor or button status, leveraging the RISC-V processor power and PSRAM.
Required Hardware
- M5Stack ToughC5 Kit (ESP32-C5HR8)
- USB Type-C cable for power and programming
- Arduino IDE with M5Stack support installed
- A push button (or use the touchscreen as input)
- Pull-up/down resistors if needed (usually internal)
Steps
- Environment Setup: In Arduino IDE, select "M5Stack ToughC5" board. Ensure the serial port is detected. The ToughC5 uses a RISC-V architecture; verify the compiler is configured for this target.
- Screen Initialization: Include the
M5GFX.hlibrary. Insetup(), callM5.Display.begin(). The 320x240 IPS screen requires specific initialization to handle brightness (853 nits) and orientation. UseM5.Display.setRotation(1)for landscape mode suitable for the rugged case. - GPIO Pin Definition: Identify the HY2.0-4P connectors. For this tutorial, we will use a GPIO pin accessible via these connectors to simulate an external input. Define the pin as
INPUT_PULLUPto avoid floating states. - Main Loop: In
loop(), read the pin state withdigitalRead(). If the state changes, update the display. UseM5.Display.fillRect()to draw colored rectangles indicating status (green for active, red for inactive). - Touch Optimization: If using the capacitive touchscreen, integrate
M5.Touchto detect presses. Compare (x,y) coordinates with drawn zones to interact with the interface without external physical buttons.
Verification
Power the ToughC5 via USB. The screen should light up with a background or solid color. Upon simulating an input (or touch press), the display must instantly change color or text. Verify that responsiveness is smooth thanks to the 8 MB of PSRAM, which allows storing graphical buffers without slowing down the processor.
Going Further
Explore integrating the RX8130CE RTC to display real-time time on the screen. You can also combine GPIO data with Wi-Fi 6 connectivity to send input states to a remote server, turning the ToughC5 into a complete IoT node with a local interface.
Other tutorials for this board
Code examples for this board
toughc5_gpio_button_buzzer.inoC++ (Arduino)toughc5_wifi6_scanner.inoC++ (Arduino)toughc5_rtc_battery_log.inoC++ (Arduino)toughc5_ili9342c_touch_ui.inoC++ (Arduino)toughc5_rs485_modbus_master.inoC++ (Arduino)toughc5-rs485-modbus-master.inoArduino C++