Problem with Pro Mico ESP32-C3 compiling ExternalWakeUp.ino low power example

I’m having a problem with Pro Mico ESP32-C3 compiling ExternalWakeUp.ino low power example. The Timer Wake Up example compiles and runs okay on the Pro Mico. ExternalWakeUp.ino compiles and runs okay on a different ESP32 platform, but not on the Pro Micro.

It would seem the problem is related to the Pro Mico ESP32-C3 board file from Sparkfun, but I’m not sure. Does anyone have any thoughts?

That board has some extra installation steps; did you do those?

Thanks, I’ll take check it out. I installed the Board Files from GitHub about a year ago when I bought my first Pro Micro ESP32-C3, but I’ll take another look.

1 Like

I followed the Software Setup steps, which were actually a modification of what I already had installed. It didn’t change the compile errors on the ExternalWakeUp.ino example.

Share the error(s), use verbose mode

Here are the compile errors:

ExternalWakeUp_CompileError.txt (11.4 KB)

Most probably you missed this line #include "esp_sleep.h"

Here are my includes:

#include <Arduino.h>
#include <driver/gpio.h> // GPIO definitions
#include <esp_sleep.h> // Sleep functions
#include <driver/rtc_io.h> // RTC IO functions

I’ll also tried the same includes in quotes " "

The errors suggest that:

  1. esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); is not recognized.
  2. rtc_gpio_pullup_dis(WAKEUP_GPIO); and rtc_gpio_pulldown_en(WAKEUP_GPIO); are also not found.
  • ESP32 vs. ESP32-C3 Differences:
    The ESP32-C3 is based on the RISC-V architecture and has a different sleep wakeup implementation than the original ESP32.

  • Different Deep Sleep Wakeup Functions:
    The esp_sleep_enable_ext0_wakeup() function does not exist for ESP32-C3. Instead, you need to use esp_sleep_enable_ext1_wakeup() or gpio_wakeup_enable().

1. Use esp_sleep_enable_ext1_wakeup() Instead

Modify your code like this:

gpio_wakeup_enable((gpio_num_t)WAKEUP_GPIO, GPIO_INTR_LOW_LEVEL);
esp_sleep_enable_gpio_wakeup();

OR

esp_sleep_enable_ext1_wakeup(1ULL << WAKEUP_GPIO, ESP_EXT1_WAKEUP_ANY_HIGH);

This enables wakeup using external GPIO signals.

2. Replace RTC GPIO Functions

Instead of:

rtc_gpio_pullup_dis(WAKEUP_GPIO);
rtc_gpio_pulldown_en(WAKEUP_GPIO);

Use:

gpio_pullup_dis((gpio_num_t)WAKEUP_GPIO);
gpio_pulldown_en((gpio_num_t)WAKEUP_GPIO);

Since ESP32-C3 does not have rtc_gpio_* functions, but you can use regular GPIO pullup/pulldown controls.

  • Replace esp_sleep_enable_ext0_wakeup() with esp_sleep_enable_ext1_wakeup() or gpio_wakeup_enable()

  • Replace rtc_gpio_pullup_dis() and rtc_gpio_pulldown_en() with gpio_pullup_dis() and gpio_pulldown_en()

  • Ensure you include:

#include <driver/gpio.h>
#include <esp_sleep.h>

Thanks for your suggestions. I can get the Pro Micro ESP32-C3 to go into the sleep mode and I get this message :

ESP-ROM:esp32c3-api1-20210207
Boot number: 1
Wakeup was not caused by deep sleep: 0
Going to sleep now

But pressing the button to bring the GPIO HIGH does not wake up the processor. I’ll post my modification of the example version of ExternalWakeUp.ino below:

<#include <Arduino.h
#include <driver/gpio.h>  // GPIO definitions
#include <esp_sleep.h>    // Sleep functions

#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO)  // 2 ^ GPIO_NUMBER in hex
#define USE_EXT0_WAKEUP          1               // 1 = EXT0 wakeup, 0 = EXT1 wakeup
#define WAKEUP_GPIO          GPIO_NUM_4          // Using GPIO 4 for wake up

RTC_DATA_ATTR int bootCount = 0;

/*
  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_GPIO:    Serial.println("Wakeup caused by GPIO"); break;
    case ESP_SLEEP_WAKEUP_TIMER:   Serial.println("Wakeup caused by timer"); break;
    case ESP_SLEEP_WAKEUP_UART:    Serial.println("Wakeup caused by UART"); 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();

#if USE_EXT0_WAKEUP
  // Using GPIO wake up method as recommended by Sparkfun
  gpio_wakeup_enable((gpio_num_t)WAKEUP_GPIO, GPIO_INTR_HIGH_LEVEL);
  esp_sleep_enable_gpio_wakeup();

  // Configure pullup/downs using standard GPIO functions
  gpio_pullup_dis((gpio_num_t)WAKEUP_GPIO);
  gpio_pulldown_en((gpio_num_t)WAKEUP_GPIO);

#else  // EXT1 WAKEUP
  //If you were to use ext1, you would use it like
  esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);
  
  // Configure GPIO pullup/pulldown
  gpio_pullup_dis((gpio_num_t)WAKEUP_GPIO);
  gpio_pulldown_en((gpio_num_t)WAKEUP_GPIO);
#endif

  //Go to sleep now
  Serial.println("Going to sleep now");
  delay(100);  // Brief delay to allow serial to finish
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}

void loop() {
  //This is not going to be called
}

Hmmm…try swapping to this. Replace:

gpio_wakeup_enable((gpio_num_t)WAKEUP_GPIO, GPIO_INTR_HIGH_LEVEL);
esp_sleep_enable_gpio_wakeup();

With:

esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1);  // 1 means HIGH level will wake up

Additionally, ensure GPIO4 is usable

Some GPIOs on the ESP32-C3 have special functions or restrictions. Try using GPIO3 or GPIO9 if GPIO4 doesn’t work.

Thanks, I made the swap and am now getting this compile error:

     'esp_sleep_enable_ext0_wakeup' was not declared in this scope; did you mean 'esp_sleep_enable_bt_wakeup'?

Round and round we go! Ha

Doh, it looks like the ESP32-C3 only supports esp_sleep_enable_ext1_wakeup() for GPIO wake-up, oops

Fix: Use EXT1 Wakeup Instead

Since esp_sleep_enable_ext0_wakeup() is unavailable on the ESP32-C3, try esp_sleep_enable_ext1_wakeup() instead.

Replace:

esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1);

With:

esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);

Here’s a sample test code:

#include <Arduino.h>
#include <esp_sleep.h>

#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO)  // Macro for EXT1
#define WAKEUP_GPIO GPIO_NUM_4                   // Use RTC-capable GPIO

RTC_DATA_ATTR int bootCount = 0;

void print_wakeup_reason() {
  esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();

  switch (wakeup_reason) {
    case ESP_SLEEP_WAKEUP_EXT1:
      Serial.println("Wakeup caused by external signal (GPIO)");
      break;
    case ESP_SLEEP_WAKEUP_TIMER:
      Serial.println("Wakeup caused by timer");
      break;
    default:
      Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason);
      break;
  }
}

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

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

  print_wakeup_reason();

  // EXT1 Wakeup (works on ESP32-C3)
  esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);

  // Configure pull-down since button pulls HIGH when pressed
  gpio_pullup_dis(WAKEUP_GPIO);
  gpio_pulldown_en(WAKEUP_GPIO);

  Serial.println("Going to sleep now");
  delay(100);
  esp_deep_sleep_start();
}

void loop() {
  // Never runs
}

I’m getting a compile error using your full sketch:

     'ESP_EXT1_WAKEUP_ANY_HIGH' was not declared in this scope;

Can you get that sketch to compile on a Pro Micro ESP32-C3?

Lemme poke around my piles of boards and see if I have a c3 laying around…

Thanks, I appreciate your help.

I’ve used the Sparkfun Pro Micro ESP32-C3 for a number of recent projects. It’s compact size makes it particularly suitable for battery-powered projects.

I did some searching and came up with this discussion on Stackoverflow:

arduino ide - Deep Sleep with EXT0 or EXT1 on ESP32-C3-MINI-1 - Stack Overflow

The sketch that works is the one in the answer reply. It seems quite simple compared to some of the others we’ve looked at. Initial current measurements: 17mA awake, 0.5mA asleep. Those measurements are with the red power LED in the circuit.

1 Like

Ah, even better!

I did not have one here to test with anyhow so…yay