🛠 Driving GPIO and LCD on ToughC5

M5Stack ToughC5 Weatherproof IoT Dev Kit (ESP32-C5) · intermediaire · Configurez les entrées-sorties et pilotez l'écran tactile IPS de 2,0 pouces pour une interface homme-machine robuste.

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

Steps

  1. 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.
  2. Screen Initialization: Include the M5GFX.h library. In setup(), call M5.Display.begin(). The 320x240 IPS screen requires specific initialization to handle brightness (853 nits) and orientation. Use M5.Display.setRotation(1) for landscape mode suitable for the rugged case.
  3. 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_PULLUP to avoid floating states.
  4. Main Loop: In loop(), read the pin state with digitalRead(). If the state changes, update the display. Use M5.Display.fillRect() to draw colored rectangles indicating status (green for active, red for inactive).
  5. Touch Optimization: If using the capacitive touchscreen, integrate M5.Touch to 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

← Back to the board 🛠 All tutorials