I am trying to get deep sleep to work on my esp32-2s Reverse TFT Feather. My goal is to have the board go into deep sleep after a given amount of time (in this example 30 seconds) and then remain in deep sleep until I press the D1 button on the board.
It appears that the board correctly goes to sleep after 30sec, but then immediately wakes up again without any button press. The test script that I have been using and getting this behavior with is below.
Does anybody have any ideas as to why this may be happening? I keep messing with it, but am not making any progress. Thanks in advance!
Code: Select all
#define BUTTON_PIN 1
#define SLEEP_TIMEOUT 30000 // 2 minutes
unsigned long lastButtonPressTime = 0;
bool deviceAwake = true;
void setup() {
Serial.begin(115200);
delay(1000); // Give time for serial to start
pinMode(BUTTON_PIN, INPUT); // Ensure internal pull-up is enabled
lastButtonPressTime = millis(); // Reset timer on wake-up
Serial.println("Setup complete");
}
void loop() {
// Serial.println("Looping");
if (digitalRead(BUTTON_PIN) == HIGH) {
Serial.println("Button Pressed");
lastButtonPressTime = millis();
delay(200); // Debounce delay
}
// Check for inactivity timeout
if (millis() - lastButtonPressTime > SLEEP_TIMEOUT) {
goToSleep();
}
}
void goToSleep() {
Serial.println("Going to sleep...");
delay(100); // Allow time for display to update
esp_sleep_enable_ext0_wakeup(GPIO_NUM_1, HIGH); // Wake up when button is pressed
Serial.println("Really going to sleep");
esp_deep_sleep_start();
}