beluga
beluga

Reputation: 322

ESP32 S3 (zero/supermini) no deep sleep with GPIO wakeup

For context: I am using this ESP32 S3 variant: https://www.waveshare.com/product/esp32-s3-zero.htm. A similar setup on an ESP32 C3 is working as expected - even with the buttons using the OneButton library at runtime.

For this simplified test a push button sits between the defined GPIO pin and Ground (expected voltages verified with a multimeter).

I am trying to put an ESP32 S3 into deep sleep after a predefined idle time and wake it up at the push of a button. Here is a simplified sketch:

#define PIN_BUTTON GPIO_NUM_7

unsigned long startTime;
unsigned long time2sleep = 15000;

void setup() {
  Serial.begin(115200);
  delay(500);

  if (esp_sleep_is_valid_wakeup_gpio(PIN_BUTTON)) {
    Serial.printf("Wakeup pin: %d\n", PIN_BUTTON);
    pinMode(PIN_BUTTON, INPUT_PULLUP);
    esp_sleep_enable_ext0_wakeup(PIN_BUTTON, 0);
  } else {
    Serial.printf("Invalid wakeup pin: %d\n", PIN_BUTTON);
  }
  startTime = millis();
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - startTime < time2sleep) {
    return;
  }
  Serial.printf("Sleeping...\n");
  delay(500);
  esp_deep_sleep_start();
}

I also tried to define ext1 with a wakeup mask, etc. However, in both cases the S3 auto-wakes shortly after esp_deep_sleep_start:

10:19:04.933 -> Wakeup pin: 7
10:19:19.835 -> Sleeping...
10:19:21.234 -> Wakeup pin: 7
10:19:35.935 -> Sleeping...
10:20:09.467 -> Wakeup pin: 7
10:20:24.229 -> Sleeping...
10:20:57.741 -> Wakeup pin: 7
10:21:12.544 -> Sleeping...

If I comment out the GPIO wakeup section the S3 stays asleep as it should. I tried other pins (i.e. 3) with the same result.

After spending a few hours on this, including reading related questions, I am at the end of my wisdom :) Does anyone have suggestions, please?

Upvotes: 0

Views: 566

Answers (1)

beluga
beluga

Reputation: 322

Ok, after researching some more I finally stumbled across ESP32 external pin wakeup with internal pullup resistor. The main trick is to:

#include "driver/rtc_io.h"

This in turn gives access to the following functions, which are hinted at in the ESP manual, but didn't compile without the include:

rtc_gpio_pullup_en(PIN_BUTTON);
rtc_gpio_pulldown_dis(PIN_BUTTON);

This makes things work as expected - also in combination with the OneButton lib.

Upvotes: 0

Related Questions