🛠 Driving E-Paper and GPIOs on M5Stack PaperDIY
Objectives
This tutorial aims to master interaction with the ED047TC1 e-paper display and the GPIO pins of the ESP32-S3 module. You will learn to display dynamic text and read the state of a physical button, exploiting PSRAM for the graphics buffer.
Required Material
- M5Stack PaperDIY Assembly Kit (ESP32-S3-WROOM-1-N16R8)
- USB-C cable for power and flashing
- Computer with Arduino IDE or VS Code (PlatformIO)
- A push button (optional for GPIO demo)
Steps
Install the M5GFX and M5Unified libraries via the Arduino Library Manager. These libraries handle the specific 8-bit parallel interface of the ED047TC1 screen.
- Environment Setup
Create a new project. Include necessary headers. The screen uses a parallel interface, requiring precise pin configuration.
- Code Initialization
#include <M5Unified.h>
void setup() {
M5.begin();
M5.Display.setBrightness(255);
M5.Display.fillScreen(GRAY_WHITE);
}
The screen offers 16 grayscale levels. Use M5.Display.drawString to display text. Note that refreshing is slow compared to LCDs.
- E-Paper Display
void loop() {
M5.Display.setCursor(10, 10);
M5.Display.printf("PaperDIY GPIO Test\n");
M5.Display.update();
delay(5000);
}
To read a button, define a pin as input with pull-up resistor. The ESP32-S3 module allows flexible GPIO management.
- GPIO Management
const int buttonPin = 4; // Check GPIO pin against schematic
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
M5.begin();
}
In the main loop, read the GPIO state and update the display if the state changes. The e-paper screen should not be refreshed too frequently to preserve the 140 mAh battery.
- Reading and Displaying
void loop() {
int state = digitalRead(buttonPin);
if (state == LOW) {
M5.Display.fillScreen(GRAY_BLACK);
} else {
M5.Display.fillScreen(GRAY_WHITE);
}
M5.Display.update();
delay(1000);
}
Verification
Compile and upload the code. The screen should display the initial text. Pressing the connected button (or shorting the pin to ground) should change the screen color. Verify that the module remains powered without overheating, thanks to the M5PM1 chip.
Further Reading
Explore using the 8 MB PSRAM to store complex images. Integrate WiFi 802.11b/g/n to receive remote commands and update the e-paper display via a web server.
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)