ESP32 not waking up from deep sleep anymore

Auroraglacialis
Posts: 4
Joined: Mon Dec 25, 2023 4:06 pm

ESP32 not waking up from deep sleep anymore

Postby Auroraglacialis » Mon Dec 25, 2023 4:17 pm

Hello. I built a tank level sensor with the ESP32 (D1 mini board) and a TOF sensor. To have it run only once a day on low power, I used deep sleep with RTC timer wakeup function and RTC GPIO pins to trigger the low power mode of the TOF module.

Code: Select all

void startDeepSleep(){
  delay(1000); //wait a moment before sleeping
  Serial.print("hibernating for [microseconds]:");
  Serial.println(uint64_t(TIME_TO_SLEEP) * uS_TO_S_FACTOR);
  Serial.flush();
  // keep xshut pin low to sleep TOF
  rtc_gpio_set_level(xsleepPin, 0);
  rtc_gpio_hold_en(xsleepPin);
  // wakeup by timer
  esp_sleep_enable_timer_wakeup(uint64_t(TIME_TO_SLEEP) * uS_TO_S_FACTOR); 
  esp_deep_sleep_start();
}
This worked out with timer set to 1 hour for testing, but I measured the current and found it was still a bit high, so I added some lines of code I read in a tutorial for hibernation mode. The sleep routine looked like this:

Code: Select all

void startDeepSleep(){
  delay(1000); //wait a moment before sleeping
  Serial.print("hibernating for [microseconds]:");
  Serial.println(uint64_t(TIME_TO_SLEEP) * uS_TO_S_FACTOR);
  Serial.flush();
  // keep xshut pin low to sleep TOF
  rtc_gpio_set_level(xsleepPin, 0);
  rtc_gpio_hold_en(xsleepPin);
  // hibernate to conserve energy
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH,   ESP_PD_OPTION_OFF);
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_OFF);
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
  esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL,         ESP_PD_OPTION_OFF);
  // wakeup by timer
  esp_sleep_enable_timer_wakeup(uint64_t(TIME_TO_SLEEP) * uS_TO_S_FACTOR); 
  esp_deep_sleep_start();
}
It did not really work out, as it did not wake up the Module anymore. Strangely enough now after I reverted to the previous code it does not wake up either!

So my question is: Is it possible to somehow "break" the RTC wakeup timer function by software or by some hardware issue I may have accidentially caused? The other functions all work out, the module still can use Wifi and TOF and send the data, just the sleep mode function is now broken. I tried to flash it with a demo code for RTC deep sleep that is in the Arduino IDE, removed all cennections to the Di module but this also does not reboot.

Code: Select all

/*
Simple Deep Sleep with Timer Wake Up
=====================================
ESP32 offers a deep sleep mode for effective power
saving as power is an important factor for IoT
applications. In this mode CPUs, most of the RAM,
and all the digital peripherals which are clocked
from APB_CLK are powered off. The only parts of
the chip which can still be powered on are:
RTC controller, RTC peripherals ,and RTC memories

This code displays the most basic deep sleep with
a timer to wake it up and how to store data in
RTC memory to use it over reboots

This code is under Public Domain License.

Author:
Pranav Cherukupalli <cherukupallip@gmail.com>
*/

#define uS_TO_S_FACTOR 1000000  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  5        /* Time ESP32 will go to sleep (in seconds) */

RTC_DATA_ATTR int bootCount = 0;

/*
Method to print the reason by which ESP32
has been awaken from sleep
*/
void print_wakeup_reason(){
  esp_sleep_wakeup_cause_t wakeup_reason;

  wakeup_reason = esp_sleep_get_wakeup_cause();

  switch(wakeup_reason)
  {
    case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
    case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
    case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
    case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
    case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
    default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
  }
}

void setup(){
  Serial.begin(9600);
  delay(1000); //Take some time to open up the Serial Monitor

  //Increment boot number and print it every reboot
  ++bootCount;
  Serial.println("Boot number: " + String(bootCount));

  //Print the wakeup reason for ESP32
  print_wakeup_reason();

  /*
  First we configure the wake up source
  We set our ESP32 to wake up every 5 seconds
  */
  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +
  " Seconds");

  /*
  Next we decide what all peripherals to shut down/keep on
  By default, ESP32 will automatically power down the peripherals
  not needed by the wakeup source, but if you want to be a poweruser
  this is for you. Read in detail at the API docs
  http://esp-idf.readthedocs.io/en/latest/api-reference/system/deep_sleep.html
  Left the line commented as an example of how to configure peripherals.
  The line below turns off all RTC peripherals in deep sleep.
  */
  //esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
  //Serial.println("Configured all RTC Peripherals to be powered down in sleep");

  /*
  Now that we have setup a wake cause and if needed setup the
  peripherals state in deep sleep, we can now start going to
  deep sleep.
  In the case that no wake up sources were provided but deep
  sleep was started, it will sleep forever unless hardware
  reset occurs.
  */
  Serial.println("Going to sleep now");
  delay(1000);
  Serial.flush(); 
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}

void loop(){
  //This is not going to be called
}
What did I do wrong and is there a way to fix it or do I need to use a fresh module and just not use those supposed hibernation functions?

Thank you

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 not waking up from deep sleep anymore

Postby lbernstone » Tue Dec 26, 2023 6:04 pm

Unless you applied high voltage, I don't think you have damaged your esp32.
In the IDE, there is an option to erase flash before upload. Using that ensures you are working from a clean install.
It sounds like you have a bench power setup where you can see the current draw. When you run the example, you can see it print all the debug statements, and then the power goes down under 1mA, but the power draw never goes back up?

Auroraglacialis
Posts: 4
Joined: Mon Dec 25, 2023 4:06 pm

Re: ESP32 not waking up from deep sleep anymore

Postby Auroraglacialis » Tue Dec 26, 2023 7:59 pm

Hi.
I am currently still arduino IDE as I started with arduino before basically moving on to esp32. For testing and flashing I use a windows laptop with USB. To measure power draw I unplug it and give voltage via the vcc pin, as I want it to run on battery, I use 3AA batteries. Then I use an multimeter to check the power draw. Not the best method but I don't yet have more fancy equipment.
However after doing all that, I now cannot get sleep with RTC wakeup to run even if I connect to the laptop with USB and flashing a demo. I tried a flash reset that I found online and that uses python, but that did not help.
I wonder if I disabled parts of the chip in EEPROM with those commands? Can I reset the EEPROM as well?
Thank you

Auroraglacialis
Posts: 4
Joined: Mon Dec 25, 2023 4:06 pm

Re: ESP32 not waking up from deep sleep anymore

Postby Auroraglacialis » Tue Dec 26, 2023 8:09 pm

Just to make sure I used a fresh d1 mini module and it works fine with the regular drop sleep in demo and in my build, which is a 3AA battery powered tank level meter. I desoldered the inboard power led and it's now using about 1mA in regular deep sleep and it did wake up every 6 hours as I planned for the test phase, so I got 4 data points since yesterday. I did not dare to try hibernation again to lower power consumption. I calculated however that now it will run maybe a month or two if I put it on daily wakeup , depending on how much power is consumed during those wake cycles, which is a bit as it needs to do 50 TOF readings to get a good precision and needs wifi for a few seconds to send the data, which takes 70mA and more

But definitely it's a flaw that is now attached to that d1 mini module. I hope I can reset it, otherwise I need to mark it as not usable for sleep mode builds

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 not waking up from deep sleep anymore

Postby lbernstone » Wed Dec 27, 2023 7:06 pm

esp32 has flash, not eeprom. If you erase the flash you erase what the EEPROM library is using. In the IDE, there is an option under tools to erase flash before uploading. No outside tools are necessary.
I have never seen a board unable to enter sleep. I am having a hard time figuring out how it would be possible to damage that function without seriously zapping the internal interrupts/timers.

Auroraglacialis
Posts: 4
Joined: Mon Dec 25, 2023 4:06 pm

Re: ESP32 not waking up from deep sleep anymore

Postby Auroraglacialis » Wed Dec 27, 2023 9:33 pm

Is there a way to do some sort of self test to see if it's an hardware issue and maybe affects other parts as well? Maybe I shorted out something or it's because I used a very large capacitor to stabilize power supply during wifi begin as it tended to shut down during those events?

Who is online

Users browsing this forum: No registered users and 75 guests