Power and sleep
Put the ESP32-C5 into deep sleep, wake it on a timer, and see which parts of the DevKitC-1 draw current the chip datasheet leaves out, with a battery-life estimate from a committed script.
You will learn
- Describe what stays powered in ESP32-C5 deep sleep and why each wake starts from reset
- Wake the chip on a timer and keep a counter in RTC memory with ESP-IDF v6.1.1
- Name the parts on the ESP32-C5-DevKitC-1 that draw current the chip datasheet does not include
- Estimate battery life from a duty cycle with a committed script, and state its assumptions
A sensor on a battery spends almost all its life asleep. This lesson shows how to put the ESP32-C5 into deep sleep and wake it on a timer, and then explains why a devkit on your bench will draw far more in “deep sleep” than the chip datasheet promises. It ends with a battery-life estimate computed by a committed script, with every assumption on the page. Our own bench measurement of the DevKitC-1 is planned and will be added to this page when it is done.
Sleep modes on the ESP32-C5
The ESP32-C5 datasheet (v1.5, Table 5-12) gives these typical currents for the chip’s low-power modes. The table does not restate the supply and temperature, while the active-mode tables just before it are for 3.3 V and 25 °C.
| Mode | What is on | Typical current |
|---|---|---|
| Light-sleep | CPU and radio powered down, peripheral clocks off, GPIOs high-impedance | 0.25 mA |
| Light-sleep | as above, peripherals also powered down | 0.06 mA |
| Deep-sleep | only the RTC timer and LP memory | 0.012 mA (12 µA) |
| Power off | CHIP_PU held low | 0.002 mA (2 µA) |
For scale, receiving on 2.4 GHz Wi-Fi costs 87 mA in the same datasheet (Table 5-7), against 0.012 mA in deep sleep. So the shape of a battery sensor is simple: wake, do the work quickly, sleep again.
In deep sleep, ESP-IDF’s sleep guide for the ESP32-C5 says the CPUs, most of the RAM and the digital peripherals lose power. Three things stay on: the RTC controller, the ULP coprocessor (the LP CPU in the datasheet) and RTC FAST memory. Because the main RAM is lost, waking from deep sleep is a restart. The bootloader runs and app_main() starts from the top. Variables you want to keep between wakes go in RTC memory with RTC_DATA_ATTR. On the ESP32-C5 there is only RTC FAST memory, and ESP-IDF keeps it powered by default.
Wake sources
ESP-IDF v6.1.1 documents these wake sources for the ESP32-C5:
| Source | API | Deep sleep | Notes |
|---|---|---|---|
| Timer | esp_sleep_enable_timer_wakeup() |
yes | microsecond argument |
| EXT1 (pin level) | esp_sleep_enable_ext1_wakeup_io() |
yes | any selected pin low, or any high |
| GPIO | esp_sleep_enable_gpio_wakeup_on_hp_periph_powerdown() |
yes | VDDPST1-powered pins only |
| ULP coprocessor | LP core program | yes | the LP core decides when to wake the main CPU |
| UART | uart_wakeup_setup() |
no | light sleep only |
Pin wake-up from deep sleep only works on pins in the low-power (LP) domain. The datasheet’s LP IO table lists LP_GPIO0 to LP_GPIO6, which are GPIO0 to GPIO6. On the DevKitC-1 the BOOT button is wired to GPIO28 (schematic V1.2), so it cannot wake the chip from deep sleep. In v6.1.1 the older esp_sleep_enable_ext1_wakeup() is deprecated in favour of the _io form.
The example
examples/l08-deep-sleep/ wakes every 60 s, counts the wakes in RTC memory, stays awake for 200 ms to stand in for real work, and sleeps again. Both times are settings in idf.py menuconfig under “Lesson 8 settings”.
// target: esp32c5 sdk: esp-idf tier: 1
// Lesson 8: wake on a timer, count wakes in RTC memory, go back to deep sleep.
// Each wake starts again from reset: the bootloader runs and app_main() is called afresh.
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_attr.h"
#include "esp_log.h"
#include "esp_sleep.h"
#include "esp_timer.h"
static const char *TAG = "l08";
// RTC memory stays powered in deep sleep, so this value survives from one wake to the next.
// It is lost when power is removed, and the code below clears it on any other kind of start.
static RTC_DATA_ATTR uint32_t s_wakes;
void app_main(void)
{
// In ESP-IDF v6.1.1 the single-cause esp_sleep_get_wakeup_cause() is deprecated:
// esp_sleep_get_wakeup_causes() returns a bitmap because several sources can fire together.
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
s_wakes++;
ESP_LOGI(TAG, "timer wake number %" PRIu32, s_wakes);
} else {
s_wakes = 0;
ESP_LOGI(TAG, "power-on or reset (causes bitmap 0x%" PRIx32 "), counter cleared", causes);
}
// Real firmware would read a sensor and publish here (lessons 5 and 7).
vTaskDelay(pdMS_TO_TICKS(CONFIG_L08_AWAKE_MS));
const uint64_t sleep_us = (uint64_t)CONFIG_L08_SLEEP_SECONDS * 1000000ULL;
ESP_ERROR_CHECK(esp_sleep_enable_timer_wakeup(sleep_us));
ESP_LOGI(TAG, "awake for %" PRId64 " ms since boot, sleeping %d s",
esp_timer_get_time() / 1000, CONFIG_L08_SLEEP_SECONDS);
esp_deep_sleep_start(); // does not return
}
One migration trap is visible here. In ESP-IDF v6.1.1, esp_sleep_get_wakeup_cause(), which returns a single cause, is marked deprecated. Its replacement, esp_sleep_get_wakeup_causes(), returns a bitmap, because two sources can fire at the same time. Test bits with BIT(ESP_SLEEP_WAKEUP_TIMER) rather than comparing for equality. Older code that calls the single-cause function gets a deprecation warning.
Build and flash as before, then open the monitor. After the first start you will see the counter cleared, then a new line every minute as the chip wakes. Monitor through the USB-UART port. Deep sleep powers down the chip’s digital peripherals, which include the ESP32-C5’s own USB Serial/JTAG controller, so expect a connection through the other port to drop at every sleep. The USB-UART port is served by the bridge chip, which stays powered from the cable.
Why the devkit draws more than the datasheet says
The 12 µA figure belongs to the chip. A devkit is a chip plus everything that makes it convenient on a bench, and most of that stays powered while the chip sleeps. We traced the power paths in Espressif’s schematic for the ESP32-C5-DevKitC-1 v1.2:
Here is each part, what feeds it and what its own documentation says. Figures are typical values with the conditions the documents give.
| Part (schematic ref) | Supplied from | Datasheet or derived figure |
|---|---|---|
| ESP32-C5 chip in the ESP32-C5-WROOM-1 module | ESP_3V3 | Deep-sleep 12 µA typ (datasheet v1.5, Table 5-12) |
| Flash and PSRAM in the module | ESP_3V3 | ESP-IDF’s sleep guide puts SPI flash standby, when it stays powered, at about 10 to 30 µA |
| Power LED D5 with R11 5.1 kΩ | VCC_3V3, so lit whenever that rail is up | No LED part number on the schematic. At most 0.647 mA at 3.3 V, computed with no LED voltage drop (upper bound) |
| Regulator feedback divider R4 680 kΩ + R20 150 kΩ | VCC_3V3 | 3.98 µA at 3.3 V (computed) |
| SY8088AAC buck regulator U2, enable tied to its input | VCC_5V | Quiescent current 40 µA typ at VIN 5 V, no load, 25 °C (Silergy AN_SY8088 Rev. 0.1). It is always on when 5 V is present |
| CP2102N-A02 USB-UART bridge U3 | VBUS of the USB-UART port only | Powered only while a cable is in that port. We could not open Silicon Labs’ datasheet in this session, so its figure is not given here |
| WS2812B RGB LED D6 | VCC_5V | The schematic names only “WS2812B”, not the version, so we have no datasheet figure we can tie to this board. The measurement will show its share |
The computed figures come from tools/calc/battery_life.py, which also confirms the regulator’s set point from its divider: 0.6 V × (1 + 680/150) = 3.32 V.
How you power the board decides which of these you pay for. Espressif’s user guide lists three options that must not be combined: the USB-C ports, the 5V and GND header pins, or the 3V3 and GND header pins. It also describes J5, a jumper between the board’s 3.3 V rail and the module. J5 is there for current measurement. The guide says to remove J5 when you supply 3.3 V at the 3V3 header pin, which feeds the module directly. With J5 removed and 3.3 V on the header pin, the module is on its own. The power LED, divider, regulator, RGB LED and USB bridge are not connected to the battery.
A battery-life estimate
tools/calc/battery_life.py computes average current over one wake period and divides the usable capacity by it. The chart below is drawn from its committed output, tools/calc/out/battery_life_l08.json. Run it with python tools/calc/battery_life.py, and run its unit tests with python -m unittest tools/calc/test_battery_life.py. Its assumptions are:
- The board is fed 3.3 V at the 3V3 header pin, from a 2000 mAh battery of which 80 % is usable. The losses and quiescent current of whatever regulator makes that 3.3 V are not modelled.
- Each wake lasts 2 s, and the radio receives for the whole of it at the datasheet’s 87 mA. Transmit bursts and CPU load are ignored. Our wake-to-publish Lab measurement will replace this guess.
- In sleep the chip draws its typical 12 µA. Flash, PSRAM and chip-to-chip spread are not included.
- Self-discharge and temperature are not modelled.
At a 5-minute interval the script gives 112.6 days for the chip figure alone and 53.6 days with J5 fitted, because the power LED alone can draw more than the average current of the whole sleep cycle. At a 1-hour interval the gap is 1,105.1 days against 93.7 days. The first number is not a promise. Over that span the cell’s self-discharge, the module’s flash and the regulator matter, and none of them is in the model. Read the chart as a comparison: once the wake interval is long, the sleep floor decides battery life, and a single always-on LED can cost you most of it. Desoldering the LED with J5 fitted brings the 1-hour estimate back to 1,036.8 days, since the divider adds only about 4 µA.
For a fuller model with several phases per wake, use the power budget worksheet.
For makers
Use deep sleep with a timer wake, and keep the awake time short. For battery tests, take J5 off and feed the module at the 3V3 header pin from a regulated 3.3 V supply, as Espressif’s guide describes. Unplug USB while measuring, because a connected cable powers the bridge chip and the regulator. Store small counters in RTC_DATA_ATTR variables and assume everything else is lost at each wake.
For product teams
Do not quote a devkit measurement as your product’s sleep current. Your board’s regulator choice, its quiescent current at your battery voltage, LEDs, pull-ups and sensor supply gating decide the floor. Budget the module’s flash standby and check the chip’s figure across temperature and units. Measure wake-to-sleep energy, not just sleep current, and repeat it on several units. Pin the ESP-IDF version: the single-cause wake API is deprecated in v6.1.1, and deprecated calls are eventually removed.
Exercise
- Set the sleep time to 10 s in menuconfig and confirm in the monitor that the counter increases at each wake.
- Press RESET while the board sleeps. Explain from the code why the counter goes back to zero.
- Run
python tools/calc/battery_life.py, then changeAWAKE_Sto 5 and run it again. At which wake interval does the extra awake time stop mattering much?
Summary
- ESP32-C5 deep sleep keeps only the RTC controller, the LP core and RTC FAST memory powered. The datasheet gives 12 µA typical for the chip.
- Each wake is a restart. Keep state in
RTC_DATA_ATTRvariables and read the wake causes as a bitmap withesp_sleep_get_wakeup_causes()in ESP-IDF v6.1.1. - Only GPIO0 to GPIO6, the LP pins, can wake the chip from deep sleep.
- On the DevKitC-1, the power LED, the SY8088 regulator, the USB-UART bridge and the RGB LED all add to the chip’s figure. J5 and the 3V3 header pin let you leave them out.
- Battery-life numbers need a committed calculation with stated assumptions, and a measurement to back them.
Further reading
- ESP32-C5 Series Datasheet v1.5, Espressif: Section 5.6 Current Consumption and Section 2.3 for the LP IO pins.
- ESP-IDF v6.1.1 Sleep Modes guide for ESP32-C5, Espressif.
- ESP32-C5-DevKitC-1 v1.2 User Guide and schematic V1.2, Espressif.
- ESP32-C5 Hardware Design Guidelines, Espressif, for the power supply design of your own board.