Dear friends welcome to the ESP32 Deep Sleep Tutorial! Today we are going to learn how to put the ESP32 chip into the Deep Sleep mode in order to conserve power and make our projects battery friendly. There is a lot to cover so let’s get started!
Intro to the ESP32 Deep Sleep Tutorial
Hello, guys, I am Nick and welcome to educ8s.tv a channel that is all about DIY electronics projects. In this channel, I share everything about the projects I build to help you develop similar projects or inspire you to start making things because it is easy, fun and creative. Subscribe to the channel now if you do not want to miss any future video.
The ESP32 chip is a fantastic new chip with great features. It offers a lot of processing power, two 32 bit cores, a lot of memory, Bluetooth and WiFi in a small and easy to use chip. One of the most interesting things about the ESP32 chip is that it offers a low-power deep sleep mode which is very easy to use. Let’s see how to use it.
Inside the ESP32 chip, we can find the two processing cores, the RAM and ROM memory, the WiFi module, the Bluetooth Module, a hardware acceleration module for cryptographic applications, the RTC module, and a lot of peripherals. Inside the RTC module, we can find a PMU (Phasor measurement unit) a small and very low power 32-bit co-processor, and 8Kbs of RAM memory. This small amount of memory is very useful as you are going to find out in a moment. Also note, even the RTC memory of the ESP32 chip is 4 times larger than the memory of the Arduino Uno.
The WiFi modules, the Processing Cores, and the Bluetooth module require a lot of current to operate. So, if we want to conserve power we have to disable them when don’t use them. This is what we are going to do now. We are going to put the ESP32 to Deep – Sleep mode where it disables everything except the RTC module. There is a light sleep mode and the Deep – Sleep mode. In Deep Sleep mode the ESP32 offers the lowest power consumption. It just needs 0.01 mAs of current in Deep Sleep mode and that’s why we are going to try today.
——————–
WHERE TO BUY
——————–
DOIT ESP32: https://educ8s.tv/part/ESP32
Firebeetle ESP32: https://educ8s.tv/part/FireBeetle
LEDs: https://educ8s.tv/part/LEDs
Resistors: https://educ8s.tv/part/Resistors
Small Breadboard: https://educ8s.tv/part/SmallBreadboard
Jumper Wires: https://educ8s.tv/part/JumperWires
Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!
[adsense]
In this mode as I said earlier, everything is disabled. The CPU cores, the WiFI module, the Bluetooth Module, the Peripherals and so on. Along with the CPU, the main memory of the chip is also disabled, so everything stored in the memory is lost forever. The only module that still works when in deep-sleep mode is the RTC module, the ultra-low-power co-processor, and its memory! So, if we save the data we want to survive the Deep-Sleep mode into the RTC memory they will be intact when we wake the chip back up.
There are three ways to wake up the chip. We can use a timer, a GPIO pin, or the co-processor. Today we are going learn how to use the timer to wake up the chip after a specific amount of time. Let’s see an example.
I have connected two LEDs to this ESP32 board. When the ESP32 boots up it lights up the yellow LED for three seconds, and then it goes into Deep-Sleep mode for 3 seconds. When it wakes up, it lights up the Green led for 3 seconds and goes back to sleep. From now on it will only blink the green LED, so the chip remembers that it is not the first time it boots up because we are using the RTC memory to store an integer value.
Let’s take a quick look at the code of this project. As you can see the code is very simple. In order to put the ESP32 into Deep-Sleep mode, all we need is two lines of code. We enable the timer with the esp_sleep_enable_timer_wakeup function, we enter the time to sleep in seconds here, and then we call the esp_deep_sleep_start function. That’s it! There is a small difference with the execution of the code though. When we use the deep-sleep function, each time the ESP32 wakes up, it executes the setup function again. The loop function is never called. All the variable values are lost, except if we save them in the RTC memory using this prefix. In this example, I save the bootCount int variable into the RTC memory in order the program to know if it is the first time it runs and turn on the correct LED. As always you can find the code of this example in the description below.
——————–
CODE
——————–
——————–
SUBSCRIBE ON YOUTUBE
——————–
Never miss a video: Subscribe to educ8s.tv
I get the following error when I compile to code for Firebeetle:
Any thoughts. (This looks like a very handy video)
Thanks
——————————————————————————————–
Arduino: 1.8.5 (Windows 10), Board: “FireBeetle-ESP32, 80MHz, 115200”.
C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Customer\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Customer\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Customer\Documents\Arduino\libraries -fqbn=esp32:DFRobot_FireBeetle-ESP32:firebeetle32:FlashFreq=80,UploadSpeed=115200 -ide-version=10805 -build-path C:\Users\Customer\AppData\Local\Temp\arduino_build_618037 -warnings=none -build-cache C:\Users\Customer\AppData\Local\Temp\arduino_cache_139263 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.xtensa-esp32-elf-gcc.path=C:\Users\Customer\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-61-gab8375a-5.2.0 -verbose C:\Users\Customer\Documents\Arduino\DeepSleepExample\DeepSleepExample.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\Customer\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\Customer\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Customer\Documents\Arduino\libraries -fqbn=esp32:DFRobot_FireBeetle-ESP32:firebeetle32:FlashFreq=80,UploadSpeed=115200 -ide-version=10805 -build-path C:\Users\Customer\AppData\Local\Temp\arduino_build_618037 -warnings=none -build-cache C:\Users\Customer\AppData\Local\Temp\arduino_cache_139263 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.xtensa-esp32-elf-gcc.path=C:\Users\Customer\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-61-gab8375a-5.2.0 -verbose C:\Users\Customer\Documents\Arduino\DeepSleepExample\DeepSleepExample.ino
Using board ‘firebeetle32’ from platform in folder: C:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7
Using core ‘esp32’ from platform in folder: C:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7
Detecting libraries used…
“C:\Users\Customer\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-61-gab8375a-5.2.0/bin/xtensa-esp32-elf-g++” -DESP_PLATFORM -DMBEDTLS_CONFIG_FILE=”mbedtls/esp_config.h” -DHAVE_CONFIG_H “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/config” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/bluedroid” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/app_update” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/bootloader_support” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/bt” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/driver” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/esp32” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/ethernet” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/fatfs” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/freertos” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/jsmn” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/log” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/mdns” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/mbedtls” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/mbedtls_port” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/newlib” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/nvs_flash” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/openssl” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/soc” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/spi_flash” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/sdmmc” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/tcpip_adapter” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/ulp” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/vfs” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/wear_levelling” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/xtensa-debug-module” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/newlib” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/coap” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/wpa_supplicant” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/expat” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/json” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/nghttp” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/lwip” -std=gnu++11 -fno-exceptions -fno-rtti -Os -g3 -Wpointer-arith -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -w -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -fno-rtti -c -w -x c++ -E -CC -DF_CPU=240000000L -DARDUINO=10805 -DARDUINO_ESP32_DEV -DARDUINO_ARCH_DFROBOT_FIREBEETLE-ESP32 -DESP32 -DCORE_DEBUG_LEVEL=0 “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7\cores\esp32” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7\variants\firebeetle32” “C:\Users\Customer\AppData\Local\Temp\arduino_build_618037\sketch\DeepSleepExample.ino.cpp” -o “nul”
Generating function prototypes…
“C:\Users\Customer\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-61-gab8375a-5.2.0/bin/xtensa-esp32-elf-g++” -DESP_PLATFORM -DMBEDTLS_CONFIG_FILE=”mbedtls/esp_config.h” -DHAVE_CONFIG_H “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/config” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/bluedroid” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/app_update” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/bootloader_support” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/bt” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/driver” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/esp32” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/ethernet” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/fatfs” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/freertos” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/jsmn” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/log” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/mdns” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/mbedtls” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/mbedtls_port” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/newlib” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/nvs_flash” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/openssl” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/soc” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/spi_flash” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/sdmmc” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/tcpip_adapter” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/ulp” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/vfs” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/wear_levelling” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/xtensa-debug-module” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/newlib” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/coap” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/wpa_supplicant” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/expat” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/json” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/nghttp” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/lwip” -std=gnu++11 -fno-exceptions -fno-rtti -Os -g3 -Wpointer-arith -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -w -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -fno-rtti -c -w -x c++ -E -CC -DF_CPU=240000000L -DARDUINO=10805 -DARDUINO_ESP32_DEV -DARDUINO_ARCH_DFROBOT_FIREBEETLE-ESP32 -DESP32 -DCORE_DEBUG_LEVEL=0 “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7\cores\esp32” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7\variants\firebeetle32” “C:\Users\Customer\AppData\Local\Temp\arduino_build_618037\sketch\DeepSleepExample.ino.cpp” -o “C:\Users\Customer\AppData\Local\Temp\arduino_build_618037\preproc\ctags_target_for_gcc_minus_e.cpp”
“C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags” -u –language-force=c++ -f – –c++-kinds=svpf –fields=KSTtzns –line-directives “C:\Users\Customer\AppData\Local\Temp\arduino_build_618037\preproc\ctags_target_for_gcc_minus_e.cpp”
Compiling sketch…
“C:\Users\Customer\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\1.22.0-61-gab8375a-5.2.0/bin/xtensa-esp32-elf-g++” -DESP_PLATFORM -DMBEDTLS_CONFIG_FILE=”mbedtls/esp_config.h” -DHAVE_CONFIG_H “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/config” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/bluedroid” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/app_update” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/bootloader_support” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/bt” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/driver” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/esp32” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/ethernet” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/fatfs” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/freertos” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/jsmn” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/log” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/mdns” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/mbedtls” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/mbedtls_port” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/newlib” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/nvs_flash” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/openssl” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/soc” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/spi_flash” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/sdmmc” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/tcpip_adapter” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/ulp” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/vfs” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/wear_levelling” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/xtensa-debug-module” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/newlib” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/coap” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/wpa_supplicant” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/expat” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/json” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/nghttp” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7/tools/sdk/include/lwip” -std=gnu++11 -fno-exceptions -fno-rtti -Os -g3 -Wpointer-arith -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -w -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -fno-rtti -MMD -c -DF_CPU=240000000L -DARDUINO=10805 -DARDUINO_ESP32_DEV -DARDUINO_ARCH_DFROBOT_FIREBEETLE-ESP32 -DESP32 -DCORE_DEBUG_LEVEL=0 “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7\cores\esp32” “-IC:\Users\Customer\AppData\Local\Arduino15\packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.7\variants\firebeetle32” “C:\Users\Customer\AppData\Local\Temp\arduino_build_618037\sketch\DeepSleepExample.ino.cpp” -o “C:\Users\Customer\AppData\Local\Temp\arduino_build_618037\sketch\DeepSleepExample.ino.cpp.o”
C:\Users\Customer\Documents\Arduino\DeepSleepExample\DeepSleepExample.ino: In function ‘void setup()’:
DeepSleepExample:35: error: ‘esp_sleep_enable_timer_wakeup’ was not declared in this scope
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
^
exit status 1
‘esp_sleep_enable_timer_wakeup’ was not declared in this scope
In your code you have not included the header file that contains the deep sleep function that you are calling. As a result I’m getting the following error when I compile your code. Please let me know which library to include to fix this error.
Thanks.
DeepSleepTest:40: error: ‘esp_sleep_enable_timer_wakeup’ was not declared in this scope
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
^
DeepSleepTest:41: error: ‘esp_deep_sleep_start’ was not declared in this scope
esp_deep_sleep_start();
^
exit status 1
‘esp_sleep_enable_timer_wakeup’ was not declared in this scope
I haven’t included that either but it works fine. Maybe it’s part of the json file for esp32 boards itself
Ali the header in current toolchain here is esp_sleep.h used to be esp_deep_sleep.h and esp_deepsleep.h
but those latter two are planned to be depretiated so should use esp_sleep.h in new code.
Ali the header in current toolchain here is esp_sleep.h used to be esp_deep_sleep.h and esp_deepsleep.h
but those latter two are planned to be depreciated so should use esp_sleep.h in new code.
Thank you very much for this excellent tutorial.
I’m currently moving my old sensors collecting some environmental data to ESP related ones as the old sensors show more and more defects and aren’t available any more (for a reasonable price)..
Most of my stuff using ESP8266 as well as ESP12 is working fine. But I’m facing a challenge with the ESP32:
It’s collecting temperature, humidity and pressure every 15minutes reading from an BME280 sensor. So I used deep_sleep as follows:
esp_sleep_enable_timer_wakeup(15minutes);
esp_deep_sleep_start();
which is working fine.
Additionally I want to count the amount of rain using the same ESP32 and an existing tripping basket. Counting those pulses works fine, too.
But how do I have to combine the two differing sources for wake up?
If I’m only specifying the GPIO wake up I’ afraid I’m loosing the ability to wake up by timer:
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13,1);
esp_deep_sleep_start();
And if I’m combining both wake-ups the time for wake up re-starts with any GPIO pulse:
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13,1);
esp_sleep_enable_timer_wakeup(15mnutes);
esp_deep_sleep_start();
On the other hand the ESP32 should be in deep_sleep with the ULP processing the GPIO pulse. Is there any need to explicitely put it in deep sleep again after a pulse was counted?
How should I do my coding?
if (wake_up_from_timer) {
…
} else { // wake-up from GPIO
…
}
I beg there’s a solution to my problem, but at the moment I simply can’t see it.
Maybe you can help?
Or you can use Toit…
Toit.io (from the team that created the V8 engine for Chrome) offers a VM and language designed for IoT development on MCUs – a balena-like platform but for the ESP32 – so you get memory-isolated apps running in parallel on battery-powered devices. Easy onboarding, smart OTAs, no more C code needed. And deep sleep is included in the out-of-the-box features. You just need to set up the Max offline in the configuration tab of your device.
Note that Toit is not open source, but with 100MB offered per month, it is essentially free for makers to use.
Hello,
Nice tuto.