Hi
I have tested this "random nerd" code, it wakes up but I need to know witch button was pressed to make if sentences do different jobs according to button pressed.
Any tip to make code reply with witch button pressed?
Code is for 1 of 3 buttons, gpio34
Serial print gives
>GPIO that triggered the wake up: GPIO inf
Witch is not what I expected
Schematic:

Testing 34:

Code:
/*
https://randomnerdtutorials.com/esp32-deep-sleep-arduino-ide-wake-up-sources/#:~:text=You%20can%20decide%20what%20peripherals,ESP32%20into%20deep%20sleep%20mode
Deep Sleep with External Wake Up
=====================================
This code displays how to use deep sleep with
an external trigger as a wake up source and how
to store data in RTC memory to use it over reboots
This code is under Public Domain License.
Hardware Connections
======================
Push Button to GPIO 34 pulled up with a 10K Ohm resistor
NOTE:
======
Only RTC IO can be used as a source for external wake
source. They are pins: 0,2,4,12-15,25-27,32-39.
Author: Pranav Cherukupalli <cherukupallip@gmail.com>
*/
#include <esp_sleep.h>
// All RTC IO pins used, 3 buttons, high when not pressed, aka Falling Edge
// GPIOs 4(alarm), 34(tare) and 35(calibrate)
// GPIO Dec HEX 9 places
// 2^4 16 000000010
// 2^34 17179869184 400000000
// 2^35 34359738368 800000000
// SUM 51539607568 C00000010
//Only gpio34 for test reason
#define BUTTON_PIN_BITMASK 0x400000000 // 2^4=10 2^34=400000000, all three:C00000010
void setup() {
Serial.begin(115200);
delay(50); //Take some time to open up the Serial Monitor
print_wakeup_reason(); //Print the wakeup reason for ESP32
print_GPIO_wake_up(); //Print the GPIO used to wake up
/*
First we configure the wake up source
We set our ESP32 to wake up for an external trigger.
There are two types for ESP32, ext0 and ext1 .
ext0 uses RTC_IO to wakeup thus requires RTC peripherals
to be on while ext1 uses RTC Controller so doesnt need
peripherals to be powered on.
Note that using internal pullups/pulldowns also requires
RTC peripherals to be turned on.
*/
//esp_deep_sleep_enable_ext0_wakeup(GPIO_NUM_34,0); //1 = High, 0 = Low (falling edge)
esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK, ESP_EXT1_WAKEUP_ALL_LOW);
//Go to sleep now
Serial.println("Sleep");
Serial.println("-------------------------");
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
void loop() {
//This is not going to be called
}
/*
Method to print the reason by which ESP32
has been awaken 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.println(GPIO_reason);
}
Serial, wake up by button connected to gpio34:
/*
08:19:11.809 -> Sleep
08:19:11.809 -> -------------------------
08:19:11.809 -> ets Jun 8 2016 00:22:57
08:19:11.809 ->
08:19:11.809 -> rst:0x5 (DEEPSLEEP_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
08:19:11.809 -> configsip: 0, SPIWP:0xee
08:19:11.809 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
08:19:11.809 -> mode:DIO, clock div:1
08:19:11.809 -> load:0x3fff0030,len:1344
08:19:11.809 -> load:0x40078000,len:13964
08:19:11.809 -> load:0x40080400,len:3600
08:19:11.809 -> entry 0x400805f0
08:19:11.903 -> Wakeup caused by external signal using RTC_CNTL
08:19:11.903 -> GPIO that triggered the wake up: GPIO inf
08:19:11.903 -> 0
08:19:11.903 -> Sleep
*/type or paste code here