🛠 Deep sleep et réveil RTC sur GPIO0

ESP32-C3 · intermediaire · Schéma : IMG-esp32-c3-intermediaire-2-deep-sleep-rtc-gpio0.svg — ESP32-C3 en deep sleep, bouton relié à GPIO0 (domaine RTC) réveillant la puce, consommation en microampères

Objectives

Put the ESP32-C3 into deep sleep and wake it up with a button using a pin from the RTC domain. The C3 typically drops to a few microamps in deep sleep — still below the 150 µA threshold of the classic ESP32 — and wakes up in less than a second. You will learn about ext0_wakeup, the RTC domain, and reading the wake-up cause.

Hardware

Complete code

#include <driver/rtc_io.h>

const uint8_t REVEIL = 0;   // GPIO0 = broche du domaine RTC

void setup {
  Serial.begin(115200);
  delay(500);

  esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause;
  if (cause == ESP_SLEEP_WAKEUP_EXT0)
    Serial.println(F("Reveille par le bouton !"));
  else
    Serial.println(F("Demarrage sur reset ou power-on"));

  rtc_gpio_init(GPIO_NUM_0);
  rtc_gpio_pullup_en(GPIO_NUM_0);    // bouton actif a l'etat bas
  rtc_gpio_hold_en(GPIO_NUM_0);

  esp_sleep_enable_ext0_wakeup(GPIO_NUM_0, 0);  // reveil si niveau BAS
  Serial.println(F("Deep sleep... appuyez sur GPIO0"));
  Serial.flush;
  esp_deep_sleep_start;
}

void loop {}   // setup est rejoue a chaque reveil

Expected verification

After the message “Deep sleep…”, the board becomes silent; pressing the button connected to GPIO0 to GND wakes it up and the console displays “Woken up by the button!”. The ammeter indicates consumption in the microamp range during sleep.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials