Hi everyone,
The other day, I was reading a discussion about ESP32 sleep modes. And it seemed to me that things were not very clear, especially about the light sleep mode. So I jumped at the opportunity to do some tests of my own, which I’m sharing with you today in the form of a comprehensive tutorial to try to clear up the fog.
Why Is This Tutorial Of Interest To You?
My initial intention was to do some experimentation with the different sleep modes of the ESP32. But while making the circuit that served as a support to illustrate my experiments, it appeared to me that I could take advantage of it to detail a lot of other things. And notably by taking care to address issues I’ve encountered in other RNT Lab posts over the last few weeks.
So I guess that even if you’re not primarily interested in sleep modes, you’ll find a lot of interesting things in this tutorial that you can use in many other applications. Take a look at it, I’m sure you’ll find something to suit your needs:
Experimenting with ESP32 sleep modes
To illustrate my point, I chose to implement a rather simple circuit:
But through this relatively simple exercise, I propose to explore some programming techniques that you can reproduce in your own projects, to properly handle buttons, or to control the time flow and regulate the frequency of execution of the main loop, or make your microcontroller able to perform several tasks simultaneously. The ultimate goal of this tutorial will be to address what makes the big difference between the different ESP32 sleep modes.
As a result, this tutorial is finally quite dense, as I tried to detail all the points I covered to be as clear as possible. I hope that I succeeded and that you will be able to apply these concepts in your own projects.
I hope you’ll enjoy it, and that I didn’t make it too boring. I hope that I’ve gone into enough detail to make sure you understand it. If there are still some grey areas, I encourage you to come and discuss with me on this thread. I will be happy to answer your questions and help you resolve your issues.
That’s great!
Thanks for sharing that!
I’ve read all parts of your tutorial and I’ve learned a lot of new stuff. Thank you.
I’ll try to come up with a summary of your tutorial to post on the Random Nerd Tutorials website.
Regards,
Sara
@Rui: Thank you for your positive feedback.
@Sara: I’m very happy that you could find some things to learn (I wonder which ones) 🙂
And thanks again for your upcoming post on RNT, which should give the turorial some visibility.
It makes me want to do more anyway 😉
Regards,
Steph
Thank you so much Jean-Pierre.
I’m trying to do my best…
But I’m not immune to making mistakes, like everyone else.
I’m like all of you: a learner.
I just try to take detailed notes on what I do 😉
Excellent, still trying to absorb it all. 🙂 On the https://m1cr0lab-esp32.github.io/sleep-modes/hibernation-mode/ page in setup() I added updateLED(); above flashActiveLED(); Coming out of sleep I was getting randomly the green light coming on. It would instantly extinguish after pressing the shiftButton though. I’m not sure why but this quick hack seemed to do the job. I put a copy of the function prototype up by your one too, seeing as we were using it before it being defined: updateLED();
That’s weird… you shouldn’t need to call updateLED()
.
Are you sure you got the ledIndex
value at the right address?
ledIndex = EEPROM.read(0);
In the hibernate()
function, are you sure you have done the commit
so that the ledIndex
backup is effective?
EEPROM.write(0, ledIndex); EEPROM.commit();
Perhaps try writing to another address in the EEPROM (making sure to reserve enough area to reach that address).
Actually, it’s been a while since I wrote this tutorial… and on the ESP32, the EEPROM library (which was an emulation of what is found on Arduino boards) is deprecated. You can try to use the Preferences library which is now recommended. This library is provided with examples and is very easy to use.
Anyway, thanks for your feedback 🙂
It’s always nice to know that the tutorial is useful to some people.
Regards,
Steph
A truly great deep-dive into sleep with the ESP32. Thank you.Â
I especially liked your notes and reference to the espressif site on the hibernation wakeup stub. I may want to use that method with the SignificationMotionDetected alert from a BNO085 IMU.