deep-sleep-timer.ino

M5Stack PaperDIY Complete Kit ESP32-S3 e-paper Development Kit · File : deep-sleep-timer.ino · Language : C++ (Arduino) · Use case : Mettre l'ESP32-S3 en sommeil profond pour économiser la batterie de 140mAh.

Uses deep sleep to minimize power consumption between tasks.

Deep sleep cuts power to most circuits, including RAM. The 140mAh battery will be preserved. Timer wake-up is handled by the internal RTC. Note that global variables are lost every sleep cycle.

deep-sleep-timer.ino

#include <Arduino.h>

#define LED_PIN 2

void setup() {
  Serial.begin(115200);
  pinMode(LED_PIN, OUTPUT);
  
  // Réveil toutes les 10 secondes
  esp_sleep_enable_timer_wakeup(10 * 1000000ULL);
  
  Serial.println("Going to sleep...");
  digitalWrite(LED_PIN, HIGH);
  delay(100);
  
  esp_deep_sleep_start();
  
  // Le code ci-dessous ne s'exécute qu'au réveil
  Serial.println("Awake!");
  digitalWrite(LED_PIN, LOW);
}

void loop() {
  // Boucle vide car le réveil relance setup()
}

← Back to the board