0
\$\begingroup\$

I am having trouble with getting the ESP32-C3-DevKit-M1 to wake up from deep sleep. I have reached out on other forums and have been told that the code works for them, but unfortunately, it does not seem to work for me.

#include "esp_sleep.h"
#include "driver/gpio.h"

#define INTERRUPT_PIN 3
RTC_DATA_ATTR int bootCount = 0;

void setup() {
   Serial.begin(115200);
   delay(1000);

   ++bootCount;
   Serial.println("Boot number: " + String(bootCount));

   print_wakeup_reason();

   Serial.println("Starting");
   delay(2000);

   for(int i=3; i!=0; i--){
   Serial.println(i);
   delay(1000);
}

Serial.println("Going to sleep now");

pinMode(INTERRUPT_PIN, INPUT);
esp_deep_sleep_enable_gpio_wakeup(1 << INTERRUPT_PIN, ESP_GPIO_WAKEUP_GPIO_HIGH);
gpio_set_direction((gpio_num_t)INTERRUPT_PIN, GPIO_MODE_INPUT);  // <<<=== Add this line
esp_deep_sleep_start();

Serial.println("This will never be printed");
}

void loop() { }

   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;
     }
}

I do not think the problem could lie in the code if multiple others have ran it and said it had worked for them, but I provided the code just in case. I will also provide the basic breadboard setup below:

Breadboard for ESP32-C3 in Deep Sleep

The resistor value acting as a pull down is 10kohms. The output and serial monitor print the following:

Serial Monitor

Output

Any help in trying to fix this issue with waking up the esp32-c3 is really appreciated, thanks!

\$\endgroup\$
2
  • \$\begingroup\$ "Other forums" - this is not a forum. It is a Q&A. \$\endgroup\$
    – JYelton
    Commented Aug 10, 2023 at 15:35
  • 3
    \$\begingroup\$ please do not post pictures of text here ... post the text instead ... some people cannot view pictures \$\endgroup\$
    – jsotola
    Commented Aug 10, 2023 at 16:55

1 Answer 1

1
\$\begingroup\$

For ESP32-C3, ESP_SLEEP_WAKEUP_EXT0 and ESP_SLEEP_WAKEUP_EXT1 are not available, and wakeup by GPIO return a wakeup_reason of 0x05(ESP_SLEEP_WAKEUP_GPIO). So you need to add it in your switch..case block.

  switch (wakeup_reason) {
    case ESP_SLEEP_WAKEUP_GPIO:    // 05 - this is used by ESP32-C3
      Serial.println("Wakeup by GPIO");
      break;
    // other cases...
  }

BTW, if you connect the switch between the GPIO pin and GND, you can set the pinMode as INPUT_PULLUP, this will save you the need for external resistor, but in this case you will need to use ESP_GPIO_WAKEUP_GPIO_LOW as wakeup trigger. This is just my personal preference of using the internal pull-up resistor instead of adding external component.

  pinMode(INTERRUPT_PIN, INPUT_PULLUP);
  esp_deep_sleep_enable_gpio_wakeup(1 << INTERRUPT_PIN, ESP_GPIO_WAKEUP_GPIO_LOW);

Reference:

Sleep Modes (ESP32-C3)

\$\endgroup\$
1
  • \$\begingroup\$ Great! Thanks so much. I'll explore on that idea of using the input_pullup as well. I appreciate the help! \$\endgroup\$
    – Abhi
    Commented Aug 11, 2023 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.