sommeil-profond.ino

ESP32-C6 · File : sommeil-profond.ino · Language : Arduino · Use case : Réduire la consommation au sommeil profond minuté

In deep sleep the SoC draws a few microamps: wake by the minute or by button, and a battery lasts months. RTC_NOINIT_ATTR keeps the wake counter across the reset.

Hardware required

An ESP32-C6 board (RISC-V 160 MHz, Wi-Fi 6 + BLE 5 + 802.15.4) such as a DevKitC-1, powered over USB. None to test; button on GPIO0 to wake manually (careful: GPIO0 is also the bootloader pin).

Wiring

Button GPIO0 to GND. On a battery build, remove the USB-serial bridge, which sips more than the sleeping SoC.

How it works

esp_sleep_enable_timer_wakeup arms the RTC clock, ext0 watches a level; esp_deep_sleep_start powers everything else down. On wake the program restarts at setup() — RAM variables are lost except RTC attributes. In the Arduino IDE (recent esp32 package), select « ESP32C6 Dev Module » then Upload; for Zigbee/Thread use ESP-IDF (idf.py set-target esp32c6).

Going further

Wake on a sensor (ext1 across several pins), or sleep between two DHT reads from the dedicated sketch.

sommeil-profond.ino

// Sommeil profond : reveil toutes les 30 s ou sur GPIO0 (LOW).
// Le compteur de reveils est conserve en RTC memory (tenu sous tension).
RTC_NOINIT_ATTR int reveils;

void setup() {
  Serial.begin(115200);
  delay(150);                       // laisser le pont USB-serial s'ouvrir
  reveils++;
  Serial.printf("\nReveil n°%d — mesure, puis dodo 30 s\n", reveils);

  // (ici : lecture capteur, envoi radio, etc.)
  Serial.printf("heap libre avant dodo : %u\n", ESP.getFreeHeap());

  esp_sleep_enable_timer_wakeup(30ULL * 1000000);          // 30 s
  esp_sleep_enable_ext0_wakeup(GPIO_NUM_0, 0);             // ou GPIO0 a LOW
  Serial.println("Entree en sommeil profond...");
  Serial.flush();
  delay(10);
  esp_deep_sleep_start();
}

void loop() {}   // jamais atteint : le deep sleep reinitialise tout

← Back to the board