ESP32 Deep Sleep: Wake up by Stopwatch and leave peripheral on

user_MicSG
Posts: 5
Joined: Thu May 27, 2021 11:56 pm

ESP32 Deep Sleep: Wake up by Stopwatch and leave peripheral on

Postby user_MicSG » Mon Apr 25, 2022 6:43 pm

Hello.
I have a simple sketch on an ESP32, which leaves one of its outputs on when it is in Deep Sleep mode and after a period of time the ESP32 exits Deep Sleep mode. To wake up from Deep Sleep there is a built-in timer that wakes you up after a period of time. But as it is, when going into Deep Sleep mode the pin output is turned off, and I wanted it to stay on. What I want is: That in Deep Sleep mode, being woken up by Timer, the RTC peripherals remain on during deep sleep.

Code:

Code: Select all


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

#define pinSaida 32

void setup() {
  Serial.begin(115200);
  delay(1000); //Take some time to open up the Serial Monitor
  pinMode(pinSaida, OUTPUT);
  digitalWrite(pinSaida, HIGH);
  delay(2000);
  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");
  Serial.flush();
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}

void loop() {
  //This is not going to be called
}
Greetings,
MicSG :D .

Who is online

Users browsing this forum: No registered users and 55 guests