gpio-button-interrupt.ino

M5Stack PaperDIY Complete Kit · File : gpio-button-interrupt.ino · Language : C++ (Arduino) · Use case : Gérer un bouton physique via interruption pour réveiller l'ESP32-S3 de sommeil profond.

Power management example using GPIO interrupts for selective wake-up.

Uses GPIO0 pin. Requires native ESP-IDF libraries. Compile with 'M5Stack-AtomS3' or 'ESP32-S3 Dev Module' selected in Arduino IDE. Press the button to wake up the board.

gpio-button-interrupt.ino

#include <Arduino.h>

#define BTN_PIN 0 // Broche GPIO0 souvent utilisée pour le boot/bouton
#define DEEP_SLEEP_TIME 60000000 // 60 secondes en microsecondes

void setup() {
  Serial.begin(115200);
  pinMode(BTN_PIN, INPUT_PULLUP);
  
  // Configure l'interruption pour réveiller de la deep sleep
  esp_sleep_enable_ext0_wakeup(GPIO_NUM_0, 0);
  
  Serial.println("Entering Deep Sleep...");
  Serial.flush();
  delay(100);
  esp_deep_sleep_start();
}

void loop() {
  Serial.println("Awake!");
  // Action à réveil
  delay(5000);
  Serial.println("Going back to sleep...");
  esp_deep_sleep_start();
}

← Back to the board