So I tried both
pinMode(2, INPUT_PULLDOWN);
and
rtc_gpio_pulldown_en(2);
rtc_gpio_pullup_dis(2);
But they don’t seem to have any effect, as it still wakes up from automatically wakes up from
deep sleep without pushing the button attached to gpio2.
Of course I could use an external resistor, but this has to fit in a watch, so every component skipped is a win. (actually it will be a watched-sized planetarium/orrery)
Does the esp32c6 even have internal pull down functionality?? if yes how to activate that so it can be used in deep sleep.
//----------------------------------------------------------------------------------------------
//Board Library : esp32 by Espressif 3.0.7
//Board Select : XIAO_ESP32C6
//----------------------------------------------------------------------------------------------
// 2025/01/23
/*
NOTE:
======
Only RTC IO can be used as a source for external wake
source. They are pins: 0,2,4,12-15,25-27,32-39.
XIAO ESP32C6 RTC IO pins : D0(0), D2(2)
XIAO ESP32C3 RTC IO pins : D0(2), D2(4)
XIAO ESP32S3 RTC IO pins : D1(2), D3(4)
*/
#include "driver/rtc_io.h"
#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex
#define USE_EXT0_WAKEUP 0 // 1 = EXT0 wakeup, 0 = EXT1 wakeup, NOTE:EXT0 compiler error
#define WAKEUP_GPIO GPIO_NUM_2 // Only RTC IO are allowed - XIAO ESP32C6 Pin example
RTC_DATA_ATTR int bootCount = 0;
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));
#if USE_EXT0_WAKEUP
esp_sleep_enable_ext0_wakeup(WAKEUP_GPIO, 1); //1 = High, 0 = Low
rtc_gpio_pullup_dis(WAKEUP_GPIO);
rtc_gpio_pulldown_en(WAKEUP_GPIO);
#else // EXT1 WAKEUP
esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
rtc_gpio_pulldown_en(WAKEUP_GPIO); // GPIO 2 is tie to GND in order to wake up in HIGH
rtc_gpio_pullup_dis(WAKEUP_GPIO); // Disable PULL_UP in order to allow it to wakeup on HIGH
#endif
Serial.println("Going to sleep now");
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
void loop() {
}
unfortunately it doesn’t work. it still immediately wakes up.
Note that I have to switch to EXT1 wakeup as otherwise I get
Compilation error: ‘esp_sleep_enable_ext0_wakeup’ was not declared in this scope; did you mean ‘esp_sleep_enable_ext1_wakeup’?
for testing I have temporarily added an external 10k pull down resistor to gpio 2. When I use that, it works fine, but when I set the program to use gpio 5 or 7 it fails and immediately wakes up when I run the program.
The only wake-up pins available on XIAO_ESP32C6 are D0 (gpio0) and D2 (gpio2).
Only RTC IO can be used as a source for external wake
source. They are pins: 0,2,4,12-15,25-27,32-39.
XIAO ESP32C6 RTC IO pins : D0(0), D2(2)
XIAO ESP32C3 RTC IO pins : D0(2), D2(4)
XIAO ESP32S3 RTC IO pins : D1(2), D3(4)
that’s confusing, because in the example code given it reads:
Bit mask of GPIO numbers which will cause wakeup.
Only GPIOswhich have RTC functionality can be used in this bit map.
For different SoCs, the related GPIOs are:
ESP32: 0, 2, 4, 12-15, 25-27, 32-39-
ESP32-S2: 0-21
ESP32-S3: 0-21
ESP32-C6: 0-7
ESP32-H2: 7-14
So I was using pins 0-7 .
According to “ESP32-C6 Technical Reference Manual 7.13 LO IO MUX Functions List”, GOIO 0-7 can be used as a wake-up source. I have checked pins 0, 1, and 2 assigned to XIAO and they wake up without any problem.
I have not checked the pads on the back as I do not have access to them.
I used a fresh esp32C6 (as the other one had things connected to D2, including an external pulldown) and added a line that calls esp_sleep_is_valid_wakeup_gpio() in order to check the validity of a port. To my surprise in now works with gpio 2, 5 and 7. All report to be valid GPIO, Back to the other board and gpio7 is waking up automatically without a button press. Running the exact same code! All though I find it very, very hard to believe myself, it looks like the other board is broken, but only slightly, as it works fine with external pulldown resistors. Very, very strange.
@msfujino now I’m a bit afraid to attach a button to gpio_7 and possibly damage this fresh esp32c6 as well. gpio 7 is labeled as MTDO, which looks like an output to me. That might conflict with the input button. Do I need to configure this in someway before pressing the button? will it go back to MTDO output when it wakes up. I’m scared…
I think it is safer not to use gpio 4-7 because it has another function assigned to it. Equally, BoardSupportPackage may initialized gpio4-7 to some function.
Are the wires soldered to the pads on the back? Or are they soldered directly to the board?