ESP32 external pin wakeup with internal pullup resistor

Viewed 2530

I am very new to working with Arduino and any kind of circuits.

I am trying to set up an ESP32 board to wake up with an external trigger by using the command esp_sleep_enable_ext0_wakeup

void setup(){
    int MY_PIN = 13;
    pinMode(MY_PIN, INPUT_PULLUP);

    int reading = digitalRead(MY_PIN);
    if(reading == 1) {
        esp_sleep_enable_ext0_wakeup(GPIO_NUM_13,0);
    }
    else {
        esp_sleep_enable_ext0_wakeup(GPIO_NUM_13,1);
    }

    // I want the board to wake up every time the state of the switch changes.

    esp_deep_sleep_start();
}

I run into troubles with this. The wakeup doesn't happen when I expect it to. I assume it has to do with using an external pull-up resistor. I didn't connect one.

Is there a way to use the internal pull-up resistor for this purpose?

I would appreciate anyone who could explain how this works in general.

The documentation says:

@note This function does not modify pin configuration. The pin is configured in esp_sleep_start, immediately before entering sleep mode.

Maybe I need to configure it correctly with esp_sleep_pd_config. Could that be the reason for the pullup resistor not working?

4 Answers

For everybody who is and will be struggling with this, the final solution is more or less combination of previous solutions.

At first you need to include library:

#include "driver/rtc_io.h"

Now you need to enable pullup/pulldown and at the same time disable the opposite one. Like this:

rtc_gpio_pullup_en(GPIO_NUM_13);
rtc_gpio_pulldown_dis(GPIO_NUM_13);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_13,0);

That's it. You don't need to enable rtc_gpio_hold_en.

I believe you need to enable the pull-up to be kept during sleep by using

    rtc_gpio_pullup_en(GPIO_NUM_13);

before the call to esp_sleep_enable_ext0_wakeup(). To do that, you also need to

#include "driver/rtc_io.h"

Did this work for you ultimately? I am also trying to trigger internal pulldowns or pullups on ESP32 to wake up from deepsleep, and it does not work. With external pullups/down, works fine. Bob

Appart from enabling pull up or pull down via rtc_gpio_pullup_en() or rtc_gpio_pulldown_en() you have to enable hold on rtc by calling rtc_gpio_hold_en().

Related