Hi
On my project I have 3 buttons. Each button must wake up ESP32 from sleep, and each button will run specific code (tare, calibrate, alarm). Each button has a pullup resistor
Due to my finished hardware, mounted physical pullup resistors, so my pin goes low when button is pressed. This is why I don't think I cant use bitmask code because it register ANY_HIGH: is that correct assumption?
//#define BUTTON_PIN_BITMASK 0x300000000
//esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH);
So my code is based on GPIOs with falling edge. (low)
I have trouble to find esp32 wake up reason when using:
esp_sleep_enable_ext0_wakeup(GPIO_NUM_35, 0); //1 = High, 0 = Low
and
uint64_t GPIO_reason = esp_sleep_get_ext0_wakeup_status();
As I understand the ext0 is different from ext1, ext1 uses bitmask and from that its possible to find the reason.
Any tip for how to code this, so each button can wake up ESP32 and execute a given code before go to sleep again?
Serial:
Button GPIO35 pushed:
Boot number: 7
Wakeup caused by external signal using RTC_IO
GPIO that triggered the wake up: GPIO inf
GPIO reason_uten log: 0
Going to sleep now
Code:
/*
Modified on Jul 12, 2021
Modified by MehranMaleki from Arduino Examples
Home
*/
#include "driver/rtc_io.h"
RTC_DATA_ATTR int bootCount = 0;
//Function for printing the reason by which ESP32 has been awakened from sleep
void print_wakeup_reason() {
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch (wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break;
}
}
/*
Method to print the GPIO that triggered the wakeup
*/
void print_GPIO_wake_up() {
uint64_t GPIO_reason = esp_sleep_get_ext1_wakeup_status();
Serial.print("GPIO that triggered the wake up: GPIO ");
Serial.println((log(GPIO_reason)) / log(2), 0);
Serial.print("GPIO reason not log() calculation: "); Serial.println(GPIO_reason);
}
void setup() {
Serial.begin(115200);
delay(500);
//Increment boot number and print it every reboot
bootCount++;
Serial.println("Boot number: " + String(bootCount));
//Print the wakeup reason for ESP32
print_wakeup_reason();
print_GPIO_wake_up();
/*
1st Step: we should configure the wake up source:
We set our ESP32 to use "ext0 OR ext1" to wake up
*/
// All RTC IO pins used, 3 buttons, high when not pressed, aka Falling Edge
// GPIOs 4(alarm), 34(tare) and 35(calibrate) = hex(2^4+2^34+2^35) des 51539607568
// GPIO Dec HEX 9 places
// 2^4 16 000000010
// 2^34 17179869184 400000000
// 2^35 34359738368 800000000
// SUM 51539607568 C00000010
//lines of code used for ext0
//rtc_gpio_pulldown_en(GPIO_NUM_35);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_35, 0); //1 = High, 0 = Low
//lines of code used for ext1
// #define BUTTON_PIN_BITMASK 0xC00000010
// esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH);
/*
2nd step: After setting up a wake cause,
we can now start going to deep sleep.
*/
Serial.println("Going to sleep now");
delay(500);
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
void loop() {
//This will not be used in Deep Sleep mode.
}