🛠 Using GPIOs with the M5Paper
Objectifs
This tutorial aims to understand how GPIO (General Purpose Input/Output) pins work on the M5Paper. You will learn to configure a pin as an output to control a simple external component, such as an LED, and to read a logical state. Although the M5Paper is primarily designed for e-Ink display, its ESP32-D0WDQ6-V3 core offers classic IoT flexibility. We will explore how to leverage these hardware resources for basic physical interactions, which are essential for any automation or connected sensor project.
Matériel nécessaire
- An M5Paper board (based on ESP32-D0WDQ6-V3)
- A USB-C cable for power and data transfer
- A computer with Arduino IDE installed (version 2.x recommended)
- A red LED and a 220-ohm resistor (optional, for physical demonstration)
- Connecting wires (jumpers) if using external components
Étapes
- Environment Setup: Open the Arduino IDE. Ensure the board manager for M5Stack kits is installed. Select the « M5Stack » board type and the serial port corresponding to your M5Paper.
- Understand the Pinout: The M5Paper exposes several GPIO pins via its Grove connector or solder pads. For this tutorial, we will use a standard GPIO pin. Note that the specific pin depends on your physical setup, but the code logic remains the same.
- Write Basic Code: Create a new sketch. In the
setup()function, define the pin as an output. Inloop(), toggle the pin state to simulate blinking or a simple command.
const int ledPin = 18; // Example of an available GPIO pin
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
- Upload: Click the « Upload » button. Monitor the serial output to confirm the code runs without errors. If you connected an LED, it should blink.
- Input Reading (Optional): Modify the code to use
pinMode(pin, INPUT_PULLUP)anddigitalRead(pin)to read the state of a push button connected to another pin.
Vérification
Open the serial monitor at 115200 bauds. If you added Serial.println() instructions, you should see logical states displayed. For the output, observe the LED behavior or measure the voltage with a multimeter between the GPIO pin and Ground (GND). A voltage near 3.3V indicates a HIGH state, and near 0V a LOW state.
Pour aller plus loin
Explore GPIO interrupts to react instantly to state changes without using delay(), freeing up the processor for other tasks like updating the e-Ink screen. You can also combine these I/Os with Wi-Fi to send data to a server.