After receiving interrupt, I want ESP32 to wake up, execute ISR, then return and finish the programmed Sleep time.
I’m not very familiar with light sleep mode.
Probably you need to combine an external wake-up and a timer wake-up.
For more information about light sleep, you can take a look at the documentation and see if you find something that works for your project:https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/sleep_modes.html#overview
Additionally, a few days ago, one of our readers created a tutorial about the different sleep modes. Here’s some valuable information about light sleep: https://iw4rr10r.github.io/esp32-sleep-modes/light-sleep-mode/
I hope this helps.
Thanks for the reply. I have to use Light Sleep since Deep Sleep does not work with GPIO wakeup. I try to use esp_sleep_enable_gpio_wakeup(rcvTip, LOW) command, but the compiler does not like the parameters: (GPIO pin#, enable on LOW). Err Message: “too many arguments to function ‘esp_err_t esp_sleep_enable_gpio_wakeup()”. I f ind Espressive documents hard to follow.
Maybe I should post this on StackOverflow.
Deep sleep works with GPIO wake-up. We have tutorials about that. Take a look at this tutorial https://rntlab.com/module-3/deep-sleep-external-wake-up/
It was working fine the last time I checked. It allows you to wake up the ESP32 when a GPIO changes its state.
Unless, it is not exactly what you’re looking for.
I’m emabarrased. I didn’t think your tutorials would discuss unusual situations like waking up with external inputs. Sorry to take your time, I should have checked the tutorials first. I tried using the external wakeup command that you discuss but it didn’t compile for me.
I will continue to work on it. Thanks again for the reply
Could you publish your code on GitHub Gist so we can help you find out what’s wrong?
Hi Sara, I posted my code on Gist. Name: ” Use GPIO interrupt to wake from Light Sleep”
Hope you can find it.
When using deep sleep, the functions you can use for wake up from external gpios are:
The X should be replaced with the GPIO number that will cause the wake-up.
The second argument, level, can be either 1 or 0. This represents the state of the GPIO that will trigger wake-up.
If you want to have more than one GPIO able to wake-up the ESP32, you can use other function:
This function accepts two arguments:
- A bitmask of the GPIO numbers that will cause the wake-up;
- Mode: the logic to wake up the ESP32. It can be:
- ESP_EXT1_WAKEUP_ALL_LOW: wake up when all GPIOs go low;
- ESP_EXT1_WAKEUP_ANY_HIGH: wake up if any of the GPIOs go high.
We show in the course how to get the bitmask of the GPIOs. But if you need further help, just ask.
If you want to use light sleep, you need to use two functions:
First, call the following function:
This function accepts as argument the GPIO you want to use as external wake-up and its level:
- GPIO number.
- GPIO wake-up type. Only GPIO_INTR_LOW_LEVEL or GPIO_INTR_HIGH_LEVEL can be used.
After setting this up, you should call this second function:
This function doesn’t accept any arguments, because the GPIOs were already defined in the other function. That’s why you get the “too many arguments” error.
Learn more about this function here: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/sleep_modes.html#_CPPv428esp_sleep_enable_gpio_wakeupv
I hope this helps.
Thank you very much for clarifying the use of Deep Sleep and Light Sleep commands. The Espressif documentation doesn’t seem very easy to follow, for me. I would not have figured out how to do this without your help. Now, I need to try your explanations in my sketch.
I’ll let you know how it works.