Waking from sleep mode with external input
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
You can use the esp_sleep_enable_ext0_wakeup() function to set up the external wakeup source.
bidrohini.bidrohiniHello 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();}
xingzhao.zhu