XIAO ESP32C3 won't wake up from Deep Sleep

Hello everyone! I have spent a couple of days trying to configure my ESP32C3 to wake up from an external voltage applied to the GPIO3 pin. I have used a multimeter to confirm that when a button is clicked, 3.3 volts are provided to pin GPIO3 (measured from the pin to the reference ground on the microcontroller). Unfortunately, this signal does not wake up the microcontroller. My code is provided below. When I compile and upload the code (then reset the microcontroller), it will print “At least we made it here 1”, “At least we made it here 2”, and “Going to sleep now”, but it never gets to either of the “Yay” statements. Does anyone know how to fix this?

#include “esp_sleep.h”
#define WakeupPin GPIO_NUM_3
RTC_DATA_ATTR int led = D10;

void setup() {
Serial.begin(115200);
delay(4000);
Serial.println(“At least we made it here 1”);
pinMode(WakeupPin,INPUT);
pinMode(led, OUTPUT);
}

void gotoSleep() {
Serial.println(“Going to sleep now”);
delay(5000);
esp_deep_sleep_enable_gpio_wakeup((1ULL << 3),ESP_GPIO_WAKEUP_GPIO_HIGH);
gpio_set_direction(GPIO_NUM_3, GPIO_MODE_INPUT);
esp_deep_sleep_start();
Serial.println(“YAY, we are awake!”);
}

void loop() {
delay(4000);
Serial.println(“At least we made it here 2”);
gotoSleep();
Serial.println(“Yay, we are back in the loop!”);
digitalWrite(led, HIGH); // turn the LED on
delay(30000); // Leave it on for 30 seconds
}

Hi there,
Welcome,
If you could post it with the code tags </> above it would be easy for others to copy it into a sketch to try it, other wise the Cut and Paste doesn’t go well. The quotes aren’t correct.

#include "esp_sleep.h"
#define WakeupPin GPIO_NUM_3
RTC_DATA_ATTR int led = D10;

void setup() {
Serial.begin(9600);
  while (!Serial)
    delay(100); // for nrf52840 with native usb
  delay(1000);
  Serial.println(" WakeUp Gpio Example");
  Serial.println("------------------------------\n");

pinMode(WakeupPin,INPUT);
pinMode(led, OUTPUT);
}

void gotoSleep() {
Serial.println("Going to sleep now");
delay(5000);
esp_deep_sleep_enable_gpio_wakeup((1ULL << 3),ESP_GPIO_WAKEUP_GPIO_LOW);
//gpio_set_direction(GPIO_NUM_3, GPIO_MODE_INPUT);
esp_deep_sleep_start();
Serial.println("YAY, we are awake!"); // THIS will never be Printed 
}

void loop() {
delay(4000);
Serial.println("LOOP ");
gotoSleep();
Serial.println("this will never be printed...!");// this will never be printed...
digitalWrite(led, HIGH); // turn the LED on
delay(30000); // Leave it on for 30 seconds
}

This works for pulling GPIO_03 or D1 LOW for wakeUP. (Tap a jumper from D1 to GND)
with yours I had to pull it UP to +v to wakeup so maybe your logic was reversed
and Set_Direction isn’t supported.

HTH
GL :slight_smile: PJ
serial output

23:28:18.292 ->  WakeUp Gpio Example
23:28:19.363 -> ------------------------------
23:28:19.363 -> 
23:28:23.356 -> LOOP 
23:28:23.356 -> Going to sleep now
23:28:41.357 ->  WakeUp Gpio Example
23:28:42.379 -> ------------------------------
23:28:42.379 -> 
23:28:46.356 -> LOOP 
23:28:46.356 -> Going to sleep now

Hello PJ! Thank you so much for the quick reply! Unfortunately, I changed my code to mirror yours, but it still doesn’t wake up when I apply the +3.3 v signal to D1. My new code is provided below in the format you recommended. I am super new to this, so I apologize for any areas where I am not following best practices and appreciate any constructive criticism. I would love to hear if you have any other ideas about why it isn’t waking up. Thanks again for the help!

#include “esp_sleep.h”
#define WakeupPin GPIO_NUM_3
RTC_DATA_ATTR int led = D10;
float starttime = millis();

void setup() {
Serial.begin(115200);
delay(4000);
Serial.println(“At least we made it here 1”);
pinMode(WakeupPin,INPUT);
pinMode(led, OUTPUT);
starttime = millis();
}

void gotoSleep() {
Serial.println(“Going to sleep now”);
delay(5000);
esp_deep_sleep_enable_gpio_wakeup((1ULL << 3),ESP_GPIO_WAKEUP_GPIO_LOW);
esp_deep_sleep_start();
Serial.println(“YAY, we are awake!”);
}

void loop() {
float time = millis()-starttime;
Serial.println(time);
if (time>5000){
gotoSleep();
}
}

Blockquote

Hi there,
Try it without the serial port stuff

#include <Arduino.h>
#include "esp32-hal-gpio.h"
#include "esp_sleep.h"
#include "driver/rtc_io.h"

//const int ledPin = 15; // Built-in LED pin on the Xiao ESP32C6
const int wakeUpPin = 2; // GPIO 2 as the wake-up pin

RTC_DATA_ATTR int bootCount = 0; // Counter to keep track of wake-ups

void setup() {
  
  // Increment boot count and print it
  bootCount++;
  //Serial.begin(9600);
  delay(2000);
  //Serial.println("Processor OUT of RESET ");
  //Serial.println("");
  //Serial.println("Boot number: " + String(bootCount));
  pinMode (LED_BUILTIN,OUTPUT);  
  pinMode(wakeUpPin, INPUT_PULLUP);

  // Blink LED 10 times
  for (int i = 0; i < 10; i++) {
    digitalWrite(LED_BUILTIN, LOW);
    delay(500);
    digitalWrite(LED_BUILTIN, HIGH);
    delay(500);
  }
  // Configure wake-up sources
  //esp_sleep_enable_ext1_wakeup(1 << wakeUpPin, ESP_EXT1_WAKEUP_ANY_HIGH); // Wake on high level
  esp_sleep_enable_timer_wakeup(30 * 1000000); // 1 minute in microseconds , 30 seconds
 // Pause for 15 seconds
  delay(15000);

//  Serial.println("Going to sleep now");
//  Serial.flush();
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  // Enter deep sleep
  esp_deep_sleep_start();
}

void loop() {
  // This function will not be called as the device enters deep sleep
}

HTH
GL :slight_smile: PJ

Finally got it to work! Thanks again for the help PJ!

1 Like