ESP.deepSleep ~ 12 hours with ESP32C3 XIAO not working

Hey,

My sketch works great. I’m using 60 minutes for deep sleep. However, for one of my projects, I only need a short wakeup twice a day, and that’s it. I thought I could achieve this, but my ESP is waking up approximately every 1.5 hours. Am I missing something here?

void goingToSleep()
{
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
//  ESP.deepSleep(60 * 60 * 1e6); // 1 hour
 ESP.deepSleep(12* 60 * 60 * 1e6); // 12 hours?
}

Hi there,
So what are the timers?
Where’s the beef?
what is the time conversion factor…?
So with this completely LIMITED, and insufficient information, One can only use logic and reason that your Variables are the wrong type. Without seeing the code your question is hard to help with.
HTH
GL :slight_smile: PJ

post the code and use the code tags </> :v:
ie.

#define uS_TO_S_FACTOR 1000000UL  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 43200 /* Time ESP32 will go to sleep (in 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 / 60) + " Minutes");
Serial.flush();
esp_deep_sleep_start();
1 Like
#define LED_PIN 2

void goingToSleep()
{
  esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
//  ESP.deepSleep(60 * 60 * 1e6); // 1 hour
 ESP.deepSleep(12* 60 * 60 * 1e6); // 12 hours?
}

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {

  digitalWrite(LED_PIN, HIGH);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  delay(1000);
  goingToSleep();
}

Thats my testsketch and its besides me on my desk - I reduced all of the code to check if I missed something, but nope!

I try your version looks good.

With your code ESP32 XIAO has ~ 40-50mA and I’m not sure it goes to really to DeepSleep

With my code the current goes down to ~48µA(!). Also when I add esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
Same result.

Have you measured the deepsleep current in one of your projects with this code?

Hi there,
No, You asked about the Time, I gave a answer to that,
Deep_Sleep requires more than that LOL forsure. The C3 does not support light sleep AFAIK? It’s different in the wakeup capabilities Too. RTC vs, Timers Vs GPIO’s etc.
My point was the Unsigned Long is what you should use.
HTH
GL :slight_smile: PJ

Btw If you look over at the Grove Expansion Flash Demo, you can see sleep for as long as you don’t press the wakeup button :blush:

Hey,

I’ve tried the example sketch from: Getting Started with Seeed Studio XIAO ESP32S3 (Sense) | Seeed Studio Wiki

/*
Simple Deep Sleep with Timer Wake Up
=====================================
This code is under Public Domain License.

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

#define uS_TO_S_FACTOR 1000000ULL  /* 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(115200);
  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_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");
  Serial.flush(); 
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}

void loop(){
  //This is not going to be called
}

The Code works, but also with longer sleep time, the esp32s3 has still ~30mA (C3 same behaviour) what is by far no deepsleep. Very Strange?

Any other ideas on this?

Next very strange part

https://docs.espressif.com/projects/esp-idf/en/v4.3.1/esp32c3/api-reference/system/sleep_modes.html#_CPPv414esp_deep_sleep8uint64_t

In the docu stands:

function is equivalent to a call to esp_deep_sleep_enable_timer_wakeup followed by a call to esp_deep_sleep_start.

BUT(!) also in the doc:

void esp_deep_sleep (uint64_t *time_in_us* )

I’ve updated platformio and arduino ide but when i inspect the deepsleep function

EspClass ESP;

void EspClass::deepSleep(uint32_t time_us)
{
    esp_deep_sleep(time_us);
}

can i change it to 64 or why do i have uint32_t???

thx