0

I'm finding it difficult to find much reliable information on how to implement deep sleep in combination with wake on external IO with ESP32C6 (ESP32-C6-DevKitC-1, rev. 1.12). After days of false starts, I've decided to go back to basics and try to implement it in the simplest way I can think of that meets my criteria. I think where I might be stumbling is related to this note in the docs:

Internal pullups and pulldowns don't work when RTC peripherals are shut down. In this case, external resistors need to be added. Alternatively, RTC peripherals (and pullups/pulldowns) may be kept enabled using esp_sleep_pd_config function.

source

I don't understand how to implement esp_sleep_pd_config() and what the best options are available for it my use case. If the answer is to use an external pullup, I can do that, but I want whatever is the best option to keep power consumption to a minimum (and at least have some comprehension of the options laid before me).

Goal:

A low power switch monitor where the switch can be open or closed for extended periods (not momentary). The board should wake on low -> high and high -> low. Upon state change, connect to WiFi, and send an insecure POST message to a local server. The following sketch only applies to the sleep/wake component.

Sketch

Here is my simple sketch just to get wake on external IO to work; changing the pin state does not get a response (I'm using Arduino IDE not ESP-IDF).

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

uint64_t gpio_pin_mask = (1ULL << 4);
RTC_DATA_ATTR unsigned btn_state;

void setup() {
  Serial.begin(115200);
  pinMode(4, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(4) == 0) {
    Serial.println("btn state 0");
    btn_state = 0;
    esp_sleep_enable_ext1_wakeup_io(gpio_pin_mask, ESP_EXT1_WAKEUP_ANY_HIGH);
    esp_deep_sleep_start();
  } else {
    Serial.println("btn state 1");
    btn_state = 1;
    esp_sleep_enable_ext1_wakeup_io(gpio_pin_mask, ESP_EXT1_WAKEUP_ANY_LOW);
    esp_deep_sleep_start();
  }
  delay(1000);
}

ESP32-C6-DevKitC-1, rev. 1.12
Arduino IDE 2.3.4 (CLI 1.1.1)

4
  • To be clear, I'm not asking for advice about anything beyond sleep/wake on external IO. I have all the other stuff built already. Commented Dec 11, 2024 at 13:19
  • 1
    Serial output is very slow compared to the CPU executing code. As written your program will probably put the CPU to sleep before it finishes outputting the message (or possibly before it even starts). Try putting delay(1000); after the serial println calls before entering deep sleep. Commented Dec 11, 2024 at 18:02
  • 1
    Thanks for the reply. I ripped apart my breadboard and put it back together and now it's working. Not sure if it was improperly wired or if one of the wires had a short. I'm going to post some drier code as an answer to show my work. Fingers crossed it will work with http client and WiFi. Commented Dec 11, 2024 at 20:09
  • 1
    Glad you got it working! Sometimes breadboards don’t make reliable contact… looks good but isn’t good. Commented Dec 11, 2024 at 21:40

1 Answer 1

1

The above logic was good, something was wrong with my prototype. Here is some drier code that I can confirm works on ESP32C6 that also implements a suggestion by @romkey. This is running with a 10K external resistor and not esp_sleep_pd_config().

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

uint64_t gpio_pin_mask = (1ULL << 4);
RTC_DATA_ATTR unsigned btn_state;

void setup() {
  Serial.begin(115200);
  pinMode(4, INPUT_PULLUP);
}

void loop() {
  btn_state = digitalRead(4);
  Serial.println("btn state " + String(btn_state));
  if (btn_state == 0) {
    esp_sleep_enable_ext1_wakeup_io(gpio_pin_mask, ESP_EXT1_WAKEUP_ANY_HIGH);
  } else {
    esp_sleep_enable_ext1_wakeup_io(gpio_pin_mask, ESP_EXT1_WAKEUP_ANY_LOW);
  }
  Serial.println("Entering sleep...");
  delay(1500);
  esp_deep_sleep_start();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.