Wakeup from Lightsleep using Button A?



  • Hello everyone,
    I am can successfully put my StickC to light sleep using a timer, but I would like to be able to wake it up either using the timer (on its own), or by pressing the A button.
    This is the code I'm using:

    #define BUTTON_PIN_BITMASK 0x2000000000 // 2^37 in hex
    
      esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
      esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH); //wake up when Button A is pressed
      Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +
      " Seconds");
      esp_light_sleep_start();
    
    

    This is the guide I used: https://randomnerdtutorials.com/esp32-external-wake-up-deep-sleep/

    My guess is that it's got something to do with the PIN 37 being interlanny pulled up or down, but I'm stuck now...
    What do you think?

    Thank you all in advance!



  • Hello @guardian5

    are you aware that the buttons, when pressed, pull their respective GPIO low (and not high)? Have you tried using ESP_EXT1_WAKEUP_ALL_LOW instead?

    For reference: M5StickC schematic.

    Thanks
    Felix



  • Thank you Felix, I solved my problem, it was clearly an internal pullup detail:

      esp_sleep_enable_ext0_wakeup(GPIO_NUM_37,0);//Configure GPIO37 as ext0 wake up source for low logic level
      gpio_pullup_en(GPIO_NUM_37);


  • Hello @guardian5

    you are welcome. I am happy to hear you got it working.

    Cheers
    Felix