(490) Unknown ESP32 saving: Light Sleep, Clock Reduction, Modem Sleep, Hibernation, and a few tricks
ฝัง
- เผยแพร่เมื่อ 7 ก.พ. 2025
- This is a replay of video 410 (during my summer break)
We all know we send our ESP32s to deep sleep to save energy. But do you know other energy-saving possibilities like light sleep and clock reduction? And what about modem sleep or hibernation?
My second channel: / hb9blawireless
Links:
ESP32 Adapter board: s.click.aliexp...
Power Profiler Kit II: www.nordicsemi...
USB-Serial Adapter 3.3V: s.click.aliexp... or amzn.to/3lBqSqD
Patreon supporter companies:
www.welectron....
The links above are usually affiliate links that support the channel (at no additional cost to you).
Supporting Material and Blog Page: www.sensorsiot.org
GitHub: www.github.com...
My Patreon Page: / andreasspiess
Discord: / discord
If you want to support the channel, please use the links below to start your shopping. No additional charges for you, but I get a commission on your purchases to buy new stuff for the channel
My Amazon.com shop: www.amazon.com...
For Banggood bit.ly/2jAQEf4
For AliExpress: For AliExpress: bit.ly/3MtXUY8 (just go on from here to your product)
For Amazon US: www.amazon.com...
For Amazon.de: amzn.to/2r0ZCYI
For Amazon UK: amzn.to/2mxBaJf
For ebay.com: ebay.to/2DuYXBp
/ spiessa
Please do not try to email me. This communication channel is reserved for my primary job
As an Amazon Associate, I earn from qualifying purchases
#no#midroll#ads
I love the recaps... it prevents my memory from forgetting things and at the same time it's nice entertainment! Enjoy the summer holidays.
Thank you. Currently, I am at Def Con in Las Vegas😁
@@AndreasSpiess Awesome! Have fun there!
Thanks for this video.
A lot of new learnings for me in a single video
hey buddy , been seeing ur videos for a while. just wanted to ask whether ordering things from china is safe or not, and which site or place to order from
Glad to hear that!
Glad to hear that!
Very thorough treatment of power consumption topics on ESP32 - thank you! A companion topic of power source selection would compliment this topic: from battery and multi-battery strategies to achieve a target battery life for a given application, on up to solar or other recharge subsystems.
Indeed a wide area. I did videos on various aspects like solar already.
@@AndreasSpiess wonderful, I will search some more through your extensive posts. Any favourites video numbers that you recommend to pair with this sleep topic? The coin cell video was very insightful, for example. Thank you for your videos - very inspiring.
The Nordic Power Profiler II is an absolute game changer if you're into low power microcontroller applications, especially those with widely varying current draw.
Its USP is its unique current measuring method, using a series of comparators to dynamically change current range, thus offering a huge dynamic range. Thus, burden voltage issues inherent to traditional static shunt resistor current measuring methods are no longer a problem.
I agree. However, you also get other such devices. But more expensive.
@@nezbrun872 I agree. I bought one of these at Andrea’s’ recommendation and it does not disappoint. I use it any time I’m developing any kind of project where power is a concern. I have just started using the digital inputs and decoding features.
@@AndreasSpiess As well as the Power Profiler II, I have a couple of SMUs and an Otii power analyser. The Power Profiler II is used almost on a daily basis. The SMUs maybe once a month. The Otii: I used it once and it's sat in a drawer ever since, its current measurement in the single digit uA range and lower is so noisy it's useless. The Power Profiler II is 1/6th the cost and offers a far better real time low current (ie, under 5uA) analysis than the Otii. My point is that the Power Profiler II's auto ranging implementation to increase dynamic range is unique to it as far as I am aware, certainly at the price point.
Link please
Thank you for the amazing video! I would love to see more videos on using low power modes with different MCUs!
I do not use many other chips...
Enjoy your summer 👍
Thanks, you too!
Yes sir thank you again. Once again you are in my head. I’m playing with solar and power consumption has been on my mind. I do need WiFi and was wondering but don’t have all the toys to know. Love it.
Rock on!
This is very good information. I am new to the ESP32 and am considering using it in a few projects as apposed to my current use of Raspberry PI, which I am familiar with and have been too lazy to learn another single board computer or microcontroller. Thanks for this and your other videos. You explain things very well.
You will like it! Raspberry Pis sometimes are too big...
I worked in my last job with a battery operated ESP32 project that reads the information from a magnetic sensor and send it using LoraWAN, and my calculations to hit the needed battery life were sub 100uA on standby, but that budget were ESP32 + sensor + lora radio.
I used the IDF to program it, Arduino is useless for any serious task that implies a micro that isn't Atmel.
All the fun stuff to manipulate the hw of the ESP is behind IDF.
And there's a lot of HW design to hit a good low sleep power consumption.
Of course the ESP32 hides a lot of quirks that needs to be addressed in the final design.
Fir professional projects, the IDF is a good choice. However, it works only for Espressif chips.
Thank you very much! Exaclty what I needed and KI didn't knew yet.
From another guy with a swiss accent.
My pleasure!
Another great video! THANKS!
My pleasure!
Another tip to save power - desolder the power LED. That thing takes 10x more power then the MCU does in deep sleep. thats what eating your battery, that tiney led!
Good tip! Thanks!
Always useful and interesting and just shared it to a group.
Thanks for sharing!
There's also a ULP co-processor and RTC memory you can use, a very low speed CPU but full capability, consuming power in nA range.
For real-world application you would want the ULP to listen to peripherals(with no interrupt capability) and wake the main CPU in certain criteria.
But realistically if you are doing very tiny application and you can bit big everything in a slow clock, you can put your whole code into ULP.
You are right. I once made a video about it ;-)
The video was useful and interesting, thank you for sharing
Glad you enjoyed it!
Great video. I was not aware you can do all these.
Thanks for watching!
great info. I was under the impresion that "WiFi.setSleep(true);" was enough for modem sleep, but i could be wrong. I do not use the ESP32 for sleep projects that often
Maybe things changed. This is a replay video.
Amazing content!
Glad you think so!
looking forward to your fall updates. Would love a recap of dev24 highlights as you see them. Also what chips you recommend for hobbyists. plus whatever else about esp32 in 2024.
I did not film at Devcon because they do not like it and had strict rules. Some people even were masked to protect their identity...
thank you
👍
No problem!
Excelente
Thank you!
Fantastic!
Glad you like it!
I have a suggestion, measure the time that every microcontroller you have takes to register an input, like a button. I saw a video of you doing it for stm32 and esp32, but I can't find it anymore! New microcontrollers like rp2040 will be awesome.
It's important for gamers to have the most low delay microcontroller.
Thanks!
The reaction time of such microcontrollers is way below 1 millisecond. So this is hardly an issue for your application. However, what they do with this information usually takes much longer.
Thanks, Grüße aus dem Ruhrgebiet
😁
Erst mal ein Like!! ...
Danke!
10:10 WiFi.mode works for me with ESP8266 even at 80Mhz. I had a project where the esp fetches time from a LAN NTP server and then updates it if the clock hits 11.30Pm the modem turns off and the internal timer starts and the wifi turns back on at 6.30Am in the morning. Never got a chance to try the command with an ESP32 though. It reduces the consumption from 130mA to just around 20mA and the esp8266 is still running everything else in the code. ADC measurements to. But I faced a issue with ESP8266 is that you cannot use the ADC too much when using WiFi so the ADC update rate is around 10S or so.
The ESP8266 has a standard clock speed of 80MHz. So, everything should work as designed.
Nice, but for battery-powered projects I prefer to use nRF24L01. I make sensors with one AAA battery on them and it works for a few months.
Also, a good idea when you do not need an internet connection.
@Andreas The Wifi library... its compiling... amazingly it works on ESP... But only WIFI, so now you can add lowpower modes to the list of things not working with the Arduino Wifi class.
(Just use the IDF functions for wifi and you might get a better result)
Thanks for the info!
Are you going to do Pico 2 review?
I am not sure. There are already many such reviews out.
@@AndreasSpiess But there are none that go into improvements of deep and lightsleep and it seems to me you are the expert for power saving.
Interesting as always, would the power consumption during deep sleep be lower if the clock frequency was set to 10mhz?
No
@@AndreasSpiess 🙄
Nice
Thanks!
I would like to see how the ESP can actually sleep at minuimum current of only a few micro-amps and wakes up by triggering an input, like a sensor contact. The datasheet mentions it can be woken up when just consuming a few microamps, bit I never saw someone doing and proving this.
In my last job I was working with a ESP32 on battery and the requirements were like 1yr of standby.
I used the ULP to wake up the main processor when the ULP detected an interrupt from a magnetic sensor.
Not only doing fw magic but also a lot of hw design is needed to hit micro amps and a good sleep
@@fersunk so in your opinion without ULP it is not possible, even when the datsheet mentions a few uA?
Power consumption in Deep-sleep mode is 10 µA, here they mean the ESP32 not the ULP right? 10uA would be perfect for battery mode... but I never saw someone succeeding in reaching only 10uA. Strange... hopefully Andreas will figure it out in the next video's.
I have 2 questions in this:
1. I cant use wifi, but can i use ESP now with lower clockrates than 80MHz?
2. Is there a way to keep the pin state on HIGH during deepsleep?
Thank you for this videos
1. Yes
2. I do not know. I never used it :-(
@@AndreasSpiess Thank you
RIP C18 on the esp [5:38]
You are a good observer!
*Summary*
## ESP32 Energy Saving Modes Summary
Here's a summary of the video's key points about optimizing your ESP32's energy consumption:
*General Tips:*
* *(**00:00:00**) Use optimized hardware:* Standard ESP32 Dev boards are power hungry. Use optimized boards, your own PCB designs, or a barebone ESP32 module.
* *(**00:10:05**) Disable unused features:* If your project doesn't need Wi-Fi or Bluetooth, avoid enabling them.
*Clock Rate Optimization:*
* *(**00:02:23**) Reduce CPU frequency:* You can significantly decrease power consumption by lowering the ESP32's clock rate from the default 240MHz.
* Reducing to 160MHz or 80MHz offers substantial savings without impacting most sensors and with full Wi-Fi/Bluetooth functionality.
* Going below 80MHz requires adjusting serial console speed and impacts Wi-Fi/Bluetooth.
* Remember that lowering clock rate reduces processing speed.
* *(**00:13:39**) Adjust clock rate dynamically:* You can change clock frequency within your sketch depending on the task.
* *(**00:10:01**) Note about Modem Sleep:* The presenter couldn't verify clear benefits of this mode and suggests avoiding it for now.
*Sleep Modes:*
* *(**00:14:19**) Light Sleep:*
* Acts like a delay with lower power consumption (around 1.5mA).
* Suitable for replacing delays when Wi-Fi/Bluetooth are not in use.
* *(**00:15:15**) Deep Sleep:*
* Most effective power saving mode, consuming only microamps.
* Requires careful management of peripherals and memory as the ESP32 reboots upon waking.
* *(00:15:32) * Disabling the ULP (Ultra Low Power) and RTC memory can further reduce power consumption during deep sleep, but eliminates persistent data storage.
*Overall:*
* *(**00:15:54**) Testing is key:* Verify functionality after implementing power saving techniques.
* *(**00:15:54**) Choose strategies that fit your needs:* Balance energy efficiency with functionality and project requirements.
I used Google Gemini 1.5 Pro to summarize the transcript.
Cost (if I didn't use the free tier): $0.1242
Time: 90.62 seconds
I added a 60 second delay to prevent a rate limit of the free tier.
Input tokens: 32723
Output tokens: 923
Thank you very much for the helpful video.
I was wondering, what could be the reason why Wi-Fi doesn't operate at frequencies below 80 MHz? How can the Wi-Fi module inside transmit symbols at such high frequencies (like 2.4 or 5 GHz) during the transmission stage ? Is the frequency required for radio transmission supplied from another source ?
The 2.4 GHz signals are produced in a radio module. The MPU has a different clock. I do not know if they are interconnected.
Thank you for your effort to achieve low power AND Wifi. I gave up. Hoping for a Zigbee solution combining Zigbee data transfer with epaper display.
I switched to ZigBee wherever possible. But only with commercial devices. I fear the ESPs will consume too much. But so far, I did not try.
@@AndreasSpiess Yes, Zigbee uses e.g. CC2530 which seems to have limited programming support.
there are commands you can use within the runtime - not in overall:
setCpuFrequencyMhz(10); - 10 MHz etc
but to make Serial working:
// Serial has to start again after CPU frequency is changed
Serial.flush();
Serial.end();
setCpuFrequencyMhz(10);
Serial.begin(115200);
Thank you for the info! Valuable!
If the clock speed is reduced then the code takes way longer to run. Judging by the area below each section of the measurements at 8:30 it looks like the most milliwatthours have been consumed at the lowest frequency of 10MHz (the total area looks way larger than at 240MHz in my opinion) Would it be fair to say that the current is in fact lower but battery life would be worse? Or am i missing something
You are correct if the processor is fully loaded. However, microcontrollers often wait for a very long time and then react to a signal. Then, a lower clock makes sense.
Oh cool
👍
As I understood in the documentation ModemSleep is nict a sleep mode, it ist just the mode, when the modem ist not working active, so it is in general turned on (initialised WiFi or BT) but is nocht sending or receiving. I researched for this a while ago for very long, because its very confusing
Modem sleep sleeps the radio. So no receiving or transmission
I think there was confusion about modem sleep. It's supposed to keep the modem alive while letting the cpu sleep, this maintains connections etc. It requires an external 32khz square wave iirc, and obviously doesn't make any sense to use without wifi. It's meant to let the modem wake up and just do the wifi book-keeping stuff.
I don't know if this is a new definition used by the new WiFi 6 functionality of some chips.
@@AndreasSpiess it seems youtube won't allow me to reply with links, but no, i'm very far from any risk of being too up to date, this was how it worked when esp32 was new, without need for ancs/ble (see watchy) it's not useful, the esp32 will never be a great device where power is at a premium, but still
Hello please make video on waveshare RP2040-ETH board it will be helpful regards
This seems to be a rather standard MCU board with an Ethernet plug. So nothing for a particular video on this channel :-(
Are you sure that you use hardware based i2c? I think with your implementation you use bitbang. I think I had interferences with f.x. wifi when using any kind of bitbang. Similar with one wire for less. m5c
I am pretty sure.
I am pretty sure.
Off topic but important: WiFi uses persistent memory. Your program will crash if you disable it. I learned this the hard way.
Interesting. I did not know that.
The problem with the sleep function in esp32 is the cpu resets from the beginning again, which makes it very hard to save power, unlike arm processors.
I agree
5:39 C18 is not happy?
You are a good observer!
Is this a reupload?
Yes, as Andreas mentioned in the video description. Re-upload of video 410.
So if my esp is in full beans mode (240mhz + wifi) then I should reboot it without initializing wifi and then enter deep sleep mode?
That depends on what you want to do with it...
How about the esp32's which have dual cpu (like the standard esp32). Doesn't the wifi run on a dedicated cpu? Can you put the other processor in deep sleep and keep wifi connected? Or do all cpu have to be in the "sleep-state"?
Both cores sleep.
It's disappointing that the ESP32 doesn't support low power BLE operation like the NRF chips.
i thought the c3 did blue tooth low power
I did not check the newer chips for power consumption. The old ones were horrible for BLE
Thank you also for this video. However, your conclusion about the sleep modes with WiFi is disappointing. I had hoped for more here. Had been researching this for hours. Lightsleep is fully automatic with WiFi. But as others have pointed out, not with Arduino IDE. Apart from the IDF ‘wifi power safe’, there are no useful examples anywhere on the net. Would you be interested in investigating this in more detail? Everyone would like to have a low power wake on wifi node! I'll keep experimenting and if needed I recompile the arduino libs with enabled advanced power options. I post if I succeed. I can also do a Swiss accent :-)
You find me in the telephone book if you found a solution! I am interested, too.
Could You get Serial (USB) with Light sleep working? No problem with Serial1, but USB ... seems not working after Light sleep
I never tried.
You keep mentioning "no WiFi" power consumption down to 10 MHz. But WiFi does not work there, as you say at the beginning? So one should really avoid this and instead turn it off? to reduce the current draw to 1/7 of the WiFi-On-value.
I made this video a few years ago (this is a replay during my summer break). I do not remember all the details anymore, but as you write, WiFi does not work on low clock frequencies. Maybe the radio still consumed power but was useless...
9:07 nearly 600mA !
You are right!
does the ESP8266 behave the same with WiFi.mode( WIFI_OFF );?
Yes. ESP8266 Works with the WiFi.mode command
great timing :P CA2RXU, 73!
73 from Vegas!
I need Deepsleep myself... only have modern sleep waking up every x hour.
Not good! Deepsleep definitely is better
I'm a programmer ... since almost ever. And I always hate when people talk about "sketches" instead of "programs". Maybe it was a marketing stunt from Arduino, to make µC programming accessible to non-programmers by coloring the bike-shed in a different color. But do we need this to non-Arduino programs?
I still cringe when people call them "apps" instead of programs... But I think that battle has been lost
If you are using arduino ide for mcu programming, maybe it takes 1 hour but in embedded c or others will take you maybe whole day or longer. You have to read the datasheet, and every mcu has its own datasheet. 😫 and sometimes you need someone to help you. can't do it by yourself "Arduino ide help you a lot if we lost arduino. We regret I telling you.
Maybe they made the distinction because the sketch is not a full program. It's a part of it but all your functions are being called by the actual main program running on the controller
As far as I recall, there was a discussion about how to call the code. I personally find the choice horrible.
@@technoman9000
"App" to me means a small program for a touch screen phone or tablet.
My brain grinds gears trying to process when someone calls desktop Microsoft Excel an "app", as I try to work out if they mean on a phone or their computer.
Thanks!
Thank you for your support!
Excellent!
Many thanks!
Thanks!
Thank you for your support!