🛠 Deep sleep et réveil RTC sur GPIO0
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
- 1 ESP32-C3 board
- 1 button between GPIO0 and GND
- Optional: micro-ammeter
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
- Requesting wake-up on a pin outside the RTC domain: ext0 only accepts GPIO0 to GPIO5 on the C3; beyond that, you need ext1 with multiple pins.
- Forgetting rtc_gpio_pullup_en: the pin floats, causing the wake-up to trigger spontaneously or never at all.
- Expecting loop to run after wake-up: in deep sleep, the chip restarts from scratch, everything happens in setup.
- Comparing to the 150 µA of the classic ESP32 without measuring your own board: the regulator, LED, and USB bridge add their own consumption.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinodht22.inoArduinooled-i2c.inoArduinoserveur-web.inoArduino