ESP32 Deep Sleep is not waking up on timer

stern1710
Posts: 4
Joined: Sun Jul 12, 2020 2:26 pm

ESP32 Deep Sleep is not waking up on timer

Postby stern1710 » Sun Jul 12, 2020 2:30 pm

Hardware:
  • []Board: ESP32 DevKit V1
  • Core Installation version: 1.0.4 (Board Manager ESP32 by Espressif Systems)
  • IDE name: Arduino 1.8.12
  • Flash Frequency: 80MHz
  • PSRAM enabled: No
  • Upload Speed: 921600
  • Computer OS: Windows 10 1909
Description:
I tried to get a bit into the deep sleep states of the ESP32 and waking it up by an timer interupt. For this, I chose to try out the sample provided under Files -> Examples -> ESP32 -> DeepSleep -> TimerWakeUp, flashed it successfully to the board (at least so I assume, works for other small projects as well) and started it up. As it unfortuanitly seems, after calling esp_deep_sleep_start(); the ESP32 is not waking up again. I tried a bit around with short time periods (e.g. 1 second), but that did not produce any other results than the board not.
The ESP32 is connected via a Micro-USB to USB-A cable to my computer, both as the data line for the Serial Monitor and flashing as well as the power source. No further components are connected to the microcontroller. Other functionalities such as WiFi or networking (using MQTT) is working fine. I don't have a second ESP32 module, so cannot verify this behaviour with other hardware sadly.
What am I doing wrong / not seeing? Anything wrong with my settings? Not having installed any the necessary libraries?

Code
  1. #define uS_TO_S_FACTOR 1000000ULL  /* Conversion factor for micro seconds to seconds */
  2. #define TIME_TO_SLEEP  5        /* Time ESP32 will go to sleep (in seconds) */
  3.  
  4. RTC_DATA_ATTR int bootCount = 0;
  5.  
  6. /*
  7. Method to print the reason by which ESP32
  8. has been awaken from sleep
  9. */
  10. void print_wakeup_reason(){
  11.   esp_sleep_wakeup_cause_t wakeup_reason;
  12.  
  13.   wakeup_reason = esp_sleep_get_wakeup_cause();
  14.  
  15.   switch(wakeup_reason)
  16.   {
  17.     case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
  18.     case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
  19.     case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
  20.     case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
  21.     case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
  22.     default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
  23.   }
  24. }
  25.  
  26. void setup(){
  27.   Serial.begin(115200);
  28.   delay(1000); //Take some time to open up the Serial Monitor
  29.  
  30.   ++bootCount;
  31.   Serial.println("Boot number: " + String(bootCount));
  32.  
  33.   print_wakeup_reason();
  34.  
  35.   esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  36.   Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +
  37.   " Seconds");
  38.  
  39.   //esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
  40.   //Serial.println("Configured all RTC Peripherals to be powered down in sleep");
  41.  
  42.   Serial.println("Going to sleep now");
  43.   Serial.flush();
  44.   esp_deep_sleep_start();
  45.   Serial.println("This will never be printed");
  46. }
  47.  
  48. void loop(){  //This is not going to be called }
Uploading output
  1. esptool.py v2.6
  2. Serial port COM3
  3. Connecting........_
  4. Chip is ESP32D0WDQ6 (revision 1)
  5. Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
  6. MAC: a4:cf:12:6c:29:78
  7. Uploading stub...
  8. Running stub...
  9. Stub running...
  10. Changing baud rate to 921600
  11. Changed.
  12. Configuring flash size...
  13. Auto-detected Flash size: 4MB
  14. Compressed 8192 bytes to 47...
  15.  
  16. Writing at 0x0000e000... (100 %)
  17. Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 1489.5 kbit/s)...
  18. Hash of data verified.
  19. Compressed 17392 bytes to 11186...
  20.  
  21. Writing at 0x00001000... (100 %)
  22. Wrote 17392 bytes (11186 compressed) at 0x00001000 in 0.2 seconds (effective 843.2 kbit/s)...
  23. Hash of data verified.
  24. Compressed 224848 bytes to 113845...
  25.  
  26. Writing at 0x00010000... (14 %)
  27. Writing at 0x00014000... (28 %)
  28. Writing at 0x00018000... (42 %)
  29. Writing at 0x0001c000... (57 %)
  30. Writing at 0x00020000... (71 %)
  31. Writing at 0x00024000... (85 %)
  32. Writing at 0x00028000... (100 %)
  33. Wrote 224848 bytes (113845 compressed) at 0x00010000 in 1.7 seconds (effective 1055.0 kbit/s)...
  34. Hash of data verified.
  35. Compressed 3072 bytes to 128...
  36.  
  37. Writing at 0x00008000... (100 %)
  38. Wrote 3072 bytes (128 compressed) at 0x00008000 in 0.0 seconds (effective 546.1 kbit/s)...
  39. Hash of data verified.
  40.  
  41. Leaving...
  42. Hard resetting via RTS pin...
Comport-Output
  1. 10:09:54.910 -> ets Jun  8 2016 00:22:57
  2. 10:09:54.943 ->
  3. 10:09:54.943 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
  4. 10:09:54.943 -> configsip: 0, SPIWP:0xee
  5. 10:09:54.943 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
  6. 10:09:54.943 -> mode:DIO, clock div:1
  7. 10:09:54.943 -> load:0x3fff0018,len:4
  8. 10:09:54.943 -> load:0x3fff001c,len:1216
  9. 10:09:54.943 -> ho 0 tail 12 room 4
  10. 10:09:54.943 -> load:0x40078000,len:9720
  11. 10:09:54.943 -> ho 0 tail 12 room 4
  12. 10:09:54.943 -> load:0x40080400,len:6352
  13. 10:09:54.943 -> entry 0x400806b8
  14. 10:09:56.090 -> Boot number: 1
  15. 10:09:56.090 -> Wakeup was not caused by deep sleep: 0
  16. 10:09:56.090 -> Setup ESP32 to sleep for every 5 Seconds
  17. 10:09:56.090 -> Going to sleep now
Thanks in advance for your ideas

euandk
Posts: 1
Joined: Thu Feb 15, 2024 1:32 am

Re: ESP32 Deep Sleep is not waking up on timer

Postby euandk » Thu Feb 15, 2024 1:38 am

This is a bit late to the party - but it might help others who have the same problem.

The issue appears to be with the Serial.flush(); on line 43.

What's happening is after the first sleep, the serial port is dropped by the system, and it's not picked up by the serial monitor again, so the second time through, when it tries to send data out the serial port it blocks on the flush() as there is nothing reading the port to clear the buffer.

If you have a more aggressive port monitor (In my case using minicom on Linux, then it works fine while minicom is reopening the port and reading the data, but blocks if I exit from minicom).

stern1710
Posts: 4
Joined: Sun Jul 12, 2020 2:26 pm

Re: ESP32 Deep Sleep is not waking up on timer

Postby stern1710 » Thu Feb 15, 2024 7:42 am

Hi and a good morning from Austria,

you are right, this is indeed quite late to the party, and I really had to read my email notification twice. Thank you for your reply nevertheless.
However, I am afraid, that the problem simply was with a corrupt devboard. I got a new one, flashed the same code and without any problem, it also awakened from deep sleep. I measured the Amps, which went down (and up again) like expected.

Who is online

Users browsing this forum: No registered users and 113 guests