Waking from sleep mode with external input

userHead Christoph.Willing 2023-04-20 21:07:42 466 Views2 Replies

I've successfully run the example sketch which puts my Firebeetle ESP32-E to sleep and wakes it up after a particular button press.

 

Separately, I can run a sketch which prints out the keys pressed on an external keypad, using the Keypad library (Mark Stanley & Alexander Brevig).

 

What I'd like to do is combine these things i.e. use the keypad output as the external input to wake the sleeping firebeetle.

 

Does anyone know how to do this, or have advice on how to proceed?

 

Thanks for any help,

chris

 

2023-05-16 18:36:44

You can use the esp_sleep_enable_ext0_wakeup() function to set up the external wakeup source.

userHeadPic bidrohini.bidrohini
2023-05-16 13:51:05

Hello Chris,

 

I don't have a keypad at the moment, but from what I understand, the interrupt function can be helpful in this case. I have written and tested the following code, and hope it is a step in the right direction. I have also found this link:

 

https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/api-reference/system/sleep_modes.html?highlight=light%20sleep

 

which explains how to use sleep mode and wake up the esp32.

 

 

#include <Arduino.h>#include <esp_sleep.h>

const int WAKEUP_PIN = 13; // Define the pin to be used for wakeup (can be modified as needed)

void setup() { // Initialize serial communication Serial.begin(115200);

 // Enter deep sleep mode enterDeepSleep();}

void loop() { // No operation needed here, because ESP32 will enter deep sleep mode in the setup function}

void enterDeepSleep() { Serial.println("Key on D7 pressed");

 // Configure an external interrupt pin to wake up the ESP32  // You can change the trigger condition to other types, such as: ESP_EXT1_WAKEUP_ANY_HIGH, ESP_EXT1_WAKEUP_ALL_LOW, etc. esp_sleep_enable_ext0_wakeup(static_cast<gpio_num_t>(WAKEUP_PIN), HIGH);

 // Enter deep sleep mode esp_deep_sleep_start();}

userHeadPic xingzhao.zhu