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.
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)
delay(1000);after the serial println calls before entering deep sleep.