How to create a wakeup from deep sleep for multiple pins without delay ?

it wakes up the esp32-s3-zero from deep sleep by a low signal on pin 1 or 2 or 3 and lights up the led accordingly.
a high signal on the pin will switch off the led.
the signal duration required to activate the led is too long, approximately 200-500ms.

is there a way to make the wake up more rapid ? i consider to build a battery powered keyboard. the deep sleep mode was intended for energy saving. the large delay makes deep sleep useless if an action upon the pin signal is required after wake up.

here is the program:

#include "esp_sleep.h"

#include "driver/gpio.h"

#include "driver/rtc_io.h"

#define RGB_BRIGHTNESS 5 // Change white brightness (max 255)

#ifdef RGB_BUILTIN

#undef RGB_BUILTIN // Remove possible previous definition

#endif

#define RGB_BUILTIN 21

void setup() {

pinMode(GPIO_NUM_1, INPUT_PULLUP);

pinMode(GPIO_NUM_2, INPUT_PULLUP);

pinMode(GPIO_NUM_3, INPUT_PULLUP);

delay(4); // Give GPIOs a brief stabilization time

// Check pin states immediately

if (digitalRead(GPIO_NUM_1) == LOW) neopixelWrite(RGB_BUILTIN, RGB_BRIGHTNESS, 0, 0); // Red

if (digitalRead(GPIO_NUM_2) == LOW) neopixelWrite(RGB_BUILTIN, 0, RGB_BRIGHTNESS, 0); // Green

if (digitalRead(GPIO_NUM_3) == LOW) neopixelWrite(RGB_BUILTIN, 0, 0, RGB_BRIGHTNESS); // Blue

if (digitalRead(GPIO_NUM_1) == HIGH) neopixelWrite(RGB_BUILTIN, 0, 0, 0); // Red

if (digitalRead(GPIO_NUM_2) == HIGH) neopixelWrite(RGB_BUILTIN, 0, 0, 0); // Green

if (digitalRead(GPIO_NUM_3) == HIGH) neopixelWrite(RGB_BUILTIN, 0, 0, 0); // Blue

//rtc_gpio_hold_dis(GPIO_NUM_1); // Disable hold if enabled

//rtc_gpio_hold_dis(GPIO_NUM_2);

//rtc_gpio_hold_dis(GPIO_NUM_3);

// Configure wake-up source (EXT1 on multiple pins, any pin LOW)

uint64_t pinMask = (1ULL << GPIO_NUM_1) | (1ULL << GPIO_NUM_2) | (1ULL << GPIO_NUM_3);

esp_sleep_enable_ext1_wakeup_io(pinMask, ESP_EXT1_WAKEUP_ANY_LOW);

// Configure pins and enable deep sleep hold

for (int pin : {GPIO_NUM_1, GPIO_NUM_2, GPIO_NUM_3} ) {

//pinMode(pin, INPUT_PULLUP); // Set as input with pull-up

rtc_gpio_pullup_en((gpio_num_t)pin); // Enable pull-up resistor

rtc_gpio_pulldown_dis((gpio_num_t)pin); // Disable pull-down resistor

rtc_gpio_hold_en((gpio_num_t)pin); // Enable hold for this pin

}

// Enter deep sleep

esp_deep_sleep_start();

}

void loop() {

// This will not be executed

}

Does this mean you have not used a Nano ESP32, but some other type?

If so you are posting in the wrong place, this is for the Nano ESP32 only.
Do you want to move it yourself (big pencil next to your post) or should I move it for you?

You might want to look at this How to get the best out of this forum before you proceed any further.

You should correct the first post by posting the code correctly, and also supplying a schematic showing how it is wired up.

2 Likes

you are right, its not the nano. its the esp32-s3-zero board from waveshare (icant find the waveshare board here). but it has the same mcu, which is the esp32-s3. so the program i posted will work on the nano, too.
the circuit is so simple that no schematic is needed, just a low signal on pin1 or pin2 or pin3. these pins are configured as input with internal pull up.
the program works, but short low signals do not trigger. in order to trigger the wakeup the low signal has to prevail for about 500ms on the pin. i am really confused what causes this massive delay.

i have to add that the clock frequency of the cpu is set to 240mhz. the flash mode is set to 120mhz

From Espressif:

The wake-up time from Deep-sleep mode is significantly longer compared to Light-sleep and Modem-sleep modes because both ROM and RAM are powered down in Deep-sleep. As a result, the CPU requires additional time for SPI booting. However, the ESP32-S3 offers a feature called the “Deep-sleep wake stub” that runs immediately upon waking from Deep-sleep, before the bootloader or any ESP-IDF code is executed.

Specifically:

  1. After waking up from Deep-sleep, the ESP32-S3 performs partial initialization.
  2. The RTC fast memory undergoes CRC validation. If the validation passes, the wake stub code is executed.
  3. Since most peripherals remain in the reset state after waking, and the SPI flash is not yet mapped, the wake stub code can only call functions that are either implemented in ROM or stored in RTC fast memory, which retains its content during Deep-sleep.

By using the wake stub functionality, you can execute some critical code immediately after waking from Deep-sleep, avoiding the delay caused by the full boot-up process. However, this functionality is limited by the size of the RTC fast memory.

RTC Memory Overview for ESP32-S3:

  • RTC fast memory: Used for the wake stub code.
  • RTC slow memory: Can store data utilized by the wake stub code or other processes.

To fully utilize this feature, ensure that:

  • The wake stub code is small enough to fit in RTC fast memory.
  • Data required by the wake stub is stored in RTC fast or RTC slow memory.

For a more detailed explanation and practical examples, check out this guide:
ESP32 Timer Wake-up from Deep Sleep

There are no dedicated sections for every manufacturer of boards. There are only dedicated sections for (most) Arduino boards.

There is however a general microcontroller section and yourn topic has been moved there.

Please honour the other request to edit your opening post and apply code tags. It makes it easier to read and copy and the forum software will display it correctly.

+1

usually failure to do so leads to very limited engagement from helpers

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.