I'm wondering if there is a solution for this.
Here is my full code:
Code: Select all
#include <Arduino.h>
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 IRAM_ATTR isr(){
detachInterrupt(digitalPinToInterrupt(32)); //because later used for wake up
Serial.println("Going to sleep now");
esp_sleep_enable_ext0_wakeup(GPIO_NUM_32,1); //1 = High, 0 = Low connected to GPIO32
esp_deep_sleep_start();
}
void setup() {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
// put your setup code here, to run once:
pinMode(32, INPUT_PULLDOWN); //pin 34-39 do not offer internal resistors; This will only work if RTC peripherals
//are on in sleep, otherwise use 10kOhm external resistor for pull down
Serial.begin(115200);
delay(1000);
Serial.println("Wake up!");
//Print the wakeup reason for ESP32
print_wakeup_reason();
attachInterrupt(digitalPinToInterrupt(32), isr, RISING);
}
void loop() {
}