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?
pins 0-2 are not available as the are connected directly to my low power stepper motor board (pololu stspin220) that drives a tiny motor. It uses the header pins on the pololu to make a nice solid connection.
It all has to fit in a watch, so it has to be tiny.
I’m not sure what you mean with “Are the wires soldered to the pads on the back? Or are they soldered directly to the board?”
And indeed the wakeup button is wired to the pad with label MTDO on the back, but that wire isn’t shown.
So I tried it again. without connecting any wires to the gpio_7 (or 5) it works, as in that it doesn’t automatically wake up and when I connect a wire from 3.3V to the pin, it wakes up. This works with both gpio5 and 7.
But when I connect a 4 cm wire to gpio_7, without connecting the other end to anything (so it is floating in mid air), it automatically wakes up. Of course there will be a weak 50Hz (or 60 hz depending on where you are living) signal on the wire, but if the internal pulldown resistor is doing its job, than that should matter.
Too me it appears that the internal pull down is not working as I think it should work.
I have connected a 20cm wire to GPIO7 and opened the other end or touched it with my finger and no false wakeups occur at all.
//----------------------------------------------------------------------------------------------
//Board Library : esp32 by Espressif 3.0.7
//Board Select : XIAO_ESP32C6
//----------------------------------------------------------------------------------------------
// 2025/01/25
/*
NOTE:
Only RTC IO can be used as a source for external wake
See ESP32-C6 Technical Reference Manual 7.13 LO IO MUX Functions List
XIAO ESP32C6 RTC IO pins : D0(0), D1(1), D2(2), Backside MTMS(4), MTDI(5), MTCK(6), MTDO(7)
EXT0 wakeup causes compaing error
*/
#include "driver/rtc_io.h"
#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex
//#define USE_EXT0_WAKEUP 0 // 0 = EXT1 wakeup, (1 = EXT0 wakeup causes compaing error)
#define WAKEUP_GPIO GPIO_NUM_7 // Only RTC IO are allowed
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 // NOTE:EXT0 wakeup causes compaing error
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); // WAKEUP_GPIO 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() {
}
that looks exactly the same as what I use for testing
#include <Arduino.h>
#include "driver/rtc_io.h"
#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO)
#define WAKEUP_GPIO GPIO_NUM_7
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));
delay(15000); // extra long delay, so i can wake it up and write new code to it
esp_sleep_enable_ext1_wakeup_io(1ULL << 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);
rtc_gpio_pullup_dis(WAKEUP_GPIO);
Serial.println("Going to sleep now");
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
void loop() {
}
it doesn’t work for me. But could you try it with a wakeup on a low signal?
(using ESP_EXT1_WAKEUP_ANY_LOW and rtc_gpio_pullup_en and rtc_gpio_pulldown_dis). That should work equally well (but could use slightly more power)