ESP32 using Deep Sleep & Light Sleep in same code

Brettjohnson7191

Joined Apr 28, 2022
23
Hello, I am working on some code right now for a project of mine. I need to be able to use light sleep and deep sleep in my code. The light sleep is used for a 10 second interval in which the ESP32 wakes up after and continues the code. This part works great as well as the rest of my code. However, when I write the code for entering deep sleep at the end of my program It keeps waking up at the 10 second interval. I believe I need to use something like esp_sleep_disable_wakeup_source(); / but am not sure what to add inside the argument any help would be appreciated. Thank you all!
[
C-like:
#define uS_TO_S_FACTOR 1000000ULL  /* Conversion factor for micro seconds to seconds */

#define TIME_TO_SLEEP  10

#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex     /* Time ESP32 will go to sleep (in seconds) */

RTC_DATA_ATTR int bootCount = 0;

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_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 WINDUP_MOTOR (){

Serial.println("RESETING.....");

digitalWrite(18, HIGH);

digitalWrite(19, LOW);

delay(5500);

digitalWrite(18,LOW);

delay(100);

}

void WINDUP_MOTOR_SLK (){

digitalWrite(18, LOW);

digitalWrite(19, HIGH);

delay(1000);

digitalWrite(19,LOW);

delay(100);

}

void REMOVE_MOTOR_FW (){

Serial.println("REMOVED");

digitalWrite(17, HIGH);

digitalWrite(16, LOW);

delay(750);

digitalWrite(17,LOW);

delay(100);

}

void REMOVE_MOTOR_RV (){

digitalWrite(17, LOW);

digitalWrite(16, HIGH);

delay(500);

digitalWrite(16,LOW);

delay(100);

}

void TRIGGER_MOTOR (){

digitalWrite(16, HIGH);

delay(750);

digitalWrite(5,LOW);

delay(100);

Serial.println("FIRED");

}

void SLEEP(){

esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);

delay(50);

Serial.println("Going to sleep now");

Serial.flush();

esp_light_sleep_start();

}

void setup() {

pinMode(18, OUTPUT);

pinMode(19, OUTPUT);

pinMode(17, OUTPUT);

pinMode(16, OUTPUT);

pinMode(5, OUTPUT);

}

void loop() {

Serial.begin(115200);

delay(50);

print_wakeup_reason();

TRIGGER_MOTOR();

delay(50);

SLEEP();

print_wakeup_reason();

WINDUP_MOTOR ();

WINDUP_MOTOR_SLK ();

REMOVE_MOTOR_FW ();

REMOVE_MOTOR_RV ();

esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,1);

Serial.println("Going to sleep now");

esp_deep_sleep_start();

}

Last edited by a moderator: