🛠 Using GPIOs with the M5Paper

M5Stack M5Paper · debutant · Apprenez à contrôler les entrées-sorties numériques du M5Paper pour interagir avec des composants externes.

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

Étapes

  1. 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.
  1. 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.
  1. Write Basic Code: Create a new sketch. In the setup() function, define the pin as an output. In loop(), 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);
}
  1. Upload: Click the « Upload » button. Monitor the serial output to confirm the code runs without errors. If you connected an LED, it should blink.
  1. Input Reading (Optional): Modify the code to use pinMode(pin, INPUT_PULLUP) and digitalRead(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.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials