According to this for an ESP32-C3 GPIO & RTC GPIO - ESP32-C3 - — ESP-IDF Programming Guide v5.2.5 documentation , you can use only GPIO pins 0, 1, 3, 4 and 5 and also, if you know what you are doing, pin 2 as well. These are "RTC" pins.
You've made some changes to the example code you have been following. For example, this macro: #define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex
What is your explanation for this change ?
Try, by using Google or other means, to determine which version of the ESP32 Arduino core that you are using. It will be something like 2.x or 3.x .
The instructions say the following. Are you using a pulldown resistor on the selected button pin? : "Push Button to GPIO 33 pulled down with a 10K Ohm resistor"
Step 1 for you, apart from answering the open questions, is to choose a valid pin for the button.
EDIT
OK. It is clear that you are using ESP32 Arduino core 3.x . Your code at least compiles under 3.x.
Most of the examples of DeepSleep I have looked at, including the one you quoted in post #3, and including the official Espressif one are intended for 2.x
EDIT 2
This appears to work using an ESP32-C3 devkitC-02. Tested with ESP32 Arduino core 3.0.5
You must use "RTC" pins but NOT 0 or 1. That is 2,3,4 and 5 work as wake up sources.
/*
ESP32 C3 Deep Sleep and wakeup
1. works with RTC pins 2, 3, 4 and 5 but not 0 and 1
see https://github.com/espressif/arduino-esp32/issues/6656
and https://github.com/espressif/arduino-esp32/issues/8447
*/
#include <Arduino.h>
#include "esp_sleep.h"
#include "driver/rtc_io.h"
#define DEBUG 1
// #define WAKEUP_PIN 1 // tidy
RTC_DATA_ATTR int bootCount;
esp_err_t errRc;
int esp_deep_sleep_enable_gpio_wakeup(uint64_t, int);
void printWakeupReason() {
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
switch (wakeup_reason) {
case ESP_SLEEP_WAKEUP_EXT1:
if (DEBUG) Serial.println("Wakeup caused by external signal using EXT1");
break;
case ESP_SLEEP_WAKEUP_EXT0:
if (DEBUG) Serial.println("Wakeup caused by external signal using EXT0");
break;
case ESP_SLEEP_WAKEUP_TIMER:
if (DEBUG) Serial.println("Wakeup caused by timer");
break;
case ESP_SLEEP_WAKEUP_GPIO:
if (DEBUG) Serial.println("Wakeup caused by GPIO");
break;
default:
if (DEBUG) Serial.printf("Wakeup not caused by deep sleep: %d\n", wakeup_reason);
break;
}
}
void setup() {
if (DEBUG) Serial.begin(115200);
delay(1000); // Give time to open the Serial Monitor
pinMode(LED_BUILTIN, OUTPUT);
for (int i = 0; i < 3; i++) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000);
digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level)
delay(1000);
}
if (DEBUG) Serial.println("starting. . . ");
bootCount++;
if (DEBUG) Serial.printf("Boot number: %d\n", bootCount);
printWakeupReason();
// errRc = esp_deep_sleep_enable_gpio_wakeup(1ull << WAKEUP_PIN, ESP_GPIO_WAKEUP_GPIO_HIGH); // $$
errRc = esp_deep_sleep_enable_gpio_wakeup(1ull | 0b11111, ESP_GPIO_WAKEUP_GPIO_HIGH); // all RTC pins can wake 0 to 5
if (DEBUG) Serial.printf("errRc (A): %d\n", (int)errRc);
if (DEBUG) Serial.println("Entering deep sleep in 5 seconds. Press the button (GPIOx pulled HIGH) to wake up."); // $$
delay(5000);
if (DEBUG) Serial.println("Entering deep sleep now.");
esp_deep_sleep_start();
}
void loop() {
}