Introduction: ESP32 Deep-Sleep
The ESP32 is the successor of the famous ESP8266. It has much more features like Bluetooth. This instructable shows you, how to deep-sleep the ESP32 and wake it up using different sources.
Step 1: Watch the Video
If you want more details, please watch this video:
Step 2: ESP32 Block Diagram and Pins
But first, let’s get an overview: The ESP32 chip has 2 processor types, the main, and the ultra-low power, or ULP processor. And it has plenty of pins, which can be used by these two processors. Most of the ESP32 pins have many different functions, which can be quite confusing if you look at the data sheet. Here is an excel sheet for an overview of the pins of the WROOM-32 module:
https://github.com/SensorsIot/ESP32-Deep-Sleep/blo...
17 pins can also be used by the ULP processor, they are called RTC_GPIOs (RTC_GPIO1 and 2 are not available on the WROOM-32 module).
There are also 10 touch sensors. And they are also connected to the ULP area. These pins will be used later on.
Step 3: Wake-Up Sources
The ESP32 supports five different modes from active where everything is “ON” to hibernation, where everything is “OFF”. Today, we concentrate on two modes: Active and deep-sleep. And we see, that even during deep-sleep, the ULP processor can be kept on. Cool. But how much current does the module consume in this state? According the Data sheet, it is 0.15 mA or 150 µA. But how can we wake the ESP32 up from its deep-sleep? With the ESP8266 we basically had two possibilities: Either reset the chip from an external source or connect GPIO16 to the reset pin for a timed wake-up. And, with the timer, we were only able to sleep for about one hour. The ESP32 has four different wake-up sources:
- The timer
- Two possibilities of external Wake-ups
- The touch pads
- ULP coprocessor wake-up
Step 4: Timer Wake-Up
The ESP8266 is only capable of sleeping for one hour.The ESP32 can sleep many years before it wakes-up. And it is no more necessary to connect pins to use the timed wake-up. Everything is internally connected.
We start the deep-sleep with esp_deep_sleep_start(); The sketch never reaches code after this statement, because, after wake-up, it starts with the execution of setup().
We also get good information on the boot procedure (e.g. reset cause).
Step 5: External Wake-Up
The next is wake-up by an external source. This was also possible with the ESP8266 by resetting the chip. Here, we get much more possibilities: We can wake-up the chip by one particular pin only. To do this, we have to select the ext0 mode and tell the chip, which pin is connected to the button. And in addition, we can decide, if we want to trigger the wake-up by a low or a high state of the pin. To find-out the pin number is a little tricky: We have to use the GPIO number of the pin, not the RTC_GPIO pin number. Fortunately, we still have our Excel sheet and we can see, that RTC_GPIO00 and GPIO36 are connected to the same pin on the WROOM-32 module.
One thing is important: You have, depending on the interrupt polarity, to connect an external pull-up or down resistor to the pin. I used a 100k resistor and it worked.
But what, if we would like to have several buttons for the wake-up? Also here, our new toy offers an elegant solution: we use the ext1 wake-up source. In this mode, we can use several pins for wake-up. Because we can declare more than one pin, we have to define a so called “mask” instead of only a pin.
Step 6: Touch Pin Wake-Up
The last one is the touch wake-up. Also this wake-up works somehow similar. The deep sleep is started with the same command, and after deep-sleep, the ESP32 also starts with the execution of setup(). The definition of the touch pin, however is different: This source uses touchInterrupts() and you attach the interrupt of each touch sensor you want to use to a “callback function”. If you do not attach the interrupt, this sensor is inactive. In addition, you have to enable touch pad wake-ups.