m5paper_deep_sleep_button.ino
Implements a critical power-saving strategy for battery-powered applications.
Deep sleep turns off the CPU and most peripherals. GPIO 39 (often linked to the PWR button or a free GPIO) is configured as input pull-up to detect a press. The e-Ink screen retains the image without power. Check the schematic to confirm the wake-up pin.
m5paper_deep_sleep_button.ino
#include <M5EPD.h>
#define WAKEUP_PIN 39 // Bouton PWR ou GPIO dédié selon montage
void setup() {
M5.begin();
M5.EPD.SetRotation(90);
// Affiche un message avant de dormir
M5EPD_Canvas canvas(&M5.EPD);
canvas.createCanvas(540, 960);
canvas.setTextSize(4);
canvas.setCursor(100, 400);
canvas.print("Sleeping...");
canvas.pushCanvas(0, 0, UPDATE_MODE_GC16);
// Configure le réveil
esp_sleep_enable_ext0_wakeup(GPIO_NUM_39, 0); // Réveil si GPIO 39 passe à LOW
// Éteint l'écran pour économiser
M5.EPD.PowerOff();
Serial.println("Going to deep sleep...");
esp_deep_sleep_start();
}
void loop() {
// Jamais atteint en sommeil profond