🛠 Controlling GPIO and e-paper display
Objectifs
This tutorial guides you through discovering digital inputs/outputs (GPIO) and displaying text on the ED047TC1 e-paper display of your M5Stack PaperDIY kit. You will learn to configure a pin as an output to control an external peripheral (or an internal LED if available) and initialize the display to write text. This kit, featuring the ESP32-S3-WROOM-1-N16R8 module, offers great flexibility with its 16 MB of flash and 8 MB of PSRAM, ideal for managing complex e-paper display buffers.
Matériel nécessaire
- An assembled M5Stack PaperDIY assembly kit.
- A USB-C cable for power and data transfer.
- A computer with the Arduino IDE installed.
- The M5Stack board manager installed in the Arduino IDE.
- Optional: A push button and a resistor to test GPIO inputs.
Étapes
Open the Arduino IDE. Go to File > Preferences and add the M5Stack board manager URL: https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/arduino/package_m5stack_index.json. Once added, go to Tools > Board > Boards Manager, search for M5Stack, and install the M5Stack package.
- Environment Preparation
In the IDE, select M5Stack > M5Paper as the board type. Select the corresponding serial port. The ESP32-S3 module uses a specific architecture; ensure compilation options (Partition Scheme) are default to optimize the 16 MB flash usage.
- Project Configuration
Go to Sketch > Include Library > Manage Libraries. Search for and install the M5GFX library, which drives the ED047TC1 screen via the 8-bit parallel interface. Also install M5Unified for simplified management of common peripherals.
- Library Installation
Create a new sketch and paste the following code. This code initializes the system, configures a GPIO pin as output (simulating control), and displays text on the e-paper screen.
- Test Code Writing
#include <M5Unified.h>
void setup() {
M5.begin();
// Initialize e-paper display
M5.Display.init();
M5.Display.fillScreen(WHITE);
M5.Display.setCursor(10, 10);
M5.Display.setTextSize(2);
M5.Display.print("Hello PaperDIY!");
// Screen update (required for e-paper)
M5.Display.update();
// Configure a GPIO pin as output (generic example)
// Use a free pin not used by display or SD
pinMode(2, OUTPUT);
}
void loop() {
// Empty loop for this static example
delay(1000);
}
Click the Upload button. Once finished, observe the screen. The text should appear black on a white background. Note that the e-paper screen does not refresh continuously like an LCD; the update() call is crucial to send data to the electronic ink pixels.
- Upload and Execution
Vérification
Verify that the text "Hello PaperDIY!" is displayed on the 4.7-inch screen (960x540 pixels). If the screen remains white, check USB connections and ensure the correct serial port is selected. Ensure the 140 mAh battery is correctly connected if you unplug USB, as the M5PM1 chip manages low-power consumption.
Pour aller plus loin
Explore the 16 gray levels offered by the ED047TC1 screen using M5.Display.setBrightness() or gradients. Try reading the state of a physical button connected to a GPIO pin using digitalRead() to interact with the display. WiFi 4 and Bluetooth 5.0 LE connectivity can then be enabled to send data remotely.
Other tutorials for this board
Code examples for this board
epaper_hello_world.inoC++wifi_web_dashboard.inoC++sdcard_logger.inoC++deep_sleep_battery.inoC++ble_beacon.inoC++gpio-button-led-basic.inoC++ (Arduino)