README.rst
1.. zephyr:code-sample:: esp32-light-sleep
2 :name: Light Sleep
3
4 Use light sleep mode on ESP32 to save power while preserving the state of the memory, CPU, and
5 peripherals.
6
7Overview
8********
9
10This example illustrates usage of light sleep mode. Unlike deep sleep mode,
11light sleep preserves the state of the memory, CPU, and peripherals. Execution
12of code on both CPUs is stopped when :c:func:`esp_light_sleep_start()` function is called.
13When the chip exits light sleep mode, execution continues at the point where it
14was stopped, and :c:func:`esp_light_sleep_start()` function returns.
15
16The example enables the following wakeup sources:
17
18* ``Timer``: wake up the chip in 2 seconds.
19* ``EXT0``: wake up the chip if a button attached to GPIO0 is pressed (i.e. if
20 GPIO0 goes low).
21
22Requirements
23************
24
25This example can be used with any ESP32 development board. Most boards have a
26button attached to GPIO0, often labelled BOOT. If the board does not have such
27button, an external button can be connected, along with a 10k pull-up resistor,
28and a 100nF capacitor to ground for debouncing.
29
30Building, Flashing and Running
31******************************
32
33.. zephyr-app-commands::
34 :zephyr-app: samples/boards/espressif/light_sleep
35 :board: esp32_devkitc_wroom/esp32/procpu
36 :goals: build flash
37 :compact:
38
39Sample Output
40=================
41ESP32 core output
42-----------------
43
44In the scenario below, the button attached to GPIO0 was pressed and held for
45about 500 ms, after the second wakeup from light sleep. The program has
46indicated the wakeup reason after each sleep iteration.
47
48.. code-block:: console
49
50 *** Booting Zephyr OS build zephyr-v3.1.0-3667-gb42e2b225ecf ***
51
52 Entering light sleep
53 Returned from light sleep, reason: timer, t=3344 ms, slept for 2001 ms
54 Entering light sleep
55 Returned from light sleep, reason: timer, t=5354 ms, slept for 2000 ms
56 Entering light sleep
57 Returned from light sleep, reason: pin, t=5885 ms, slept for 521 ms
58 Waiting for GPIO0 to go high...
59 Entering light sleep
60 Returned from light sleep, reason: timer, t=8765 ms, slept for 2000 ms
61 Entering light sleep
62 Returned from light sleep, reason: timer, t=10776 ms, slept for 2001 ms
63 Entering light sleep
64
65Troubleshooting
66***************
67
68If pressing the button attached to GPIO0 does not affect program behavior,
69check DTR/RTS configuration in the serial monitor. This is not necessary for
70IDF monitor, but for other tools it might be necessary to set DTR and RTS line
71state to "disabled" or "de-asserted".
72