Hi PJ_Glasso,
Thanks for the response, I have managed to look into the documentation a bit more and found out that the RTC GPIO Pin needs to be pulled up or down using the rtc_gpio_pullup_en commands instead of the pinmode way. I have attached the code that allowed me to perform deep sleep with the push button.
#include "driver/rtc_io.h"
const gpio_num_t WAKEUP_BUTTON_PIN = GPIO_NUM_2; // Define GPIO_NUM_2 as a const
RTC_DATA_ATTR int bootCount = 0;
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;
}
}
void setup(){
Serial.begin(115200);
delay(1000); //Take some time to open up the Serial Monitor
//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));
//Print the wakeup reason for ESP32
print_wakeup_reason();
rtc_gpio_pullup_en(WAKEUP_BUTTON_PIN); // Use the const here
rtc_gpio_pulldown_dis(WAKEUP_BUTTON_PIN); // Use the const here
esp_sleep_enable_ext0_wakeup(WAKEUP_BUTTON_PIN, 0); // When the button is pressed, wake up
//Go to sleep now
Serial.println("Going to sleep now");
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
void loop(){
//This is not going to be called
}