If you're just joining us, we just finished upgrading a small Christmas tree with Neopixel goodness. We also implemented a deep sleep mode for all the times the tree isn't glowing. I'm sure you trust me when I say that deep sleep was important, but just how important was it? How can we be sure?
For that, we need to be able to measure our power consumption, and we'll do that now with a Nordic Power Profiler.
![Angled shot of Nordic nrF Power Profiler board.](https://cdn-shop.adafruit.com/640x480/5048-00.jpg)
The Nordic Power Profiler can provide power to a circuit at anywhere from 0.8 to 5 volts, and measure how much energy that circuit is consuming. We're going to set it to 3.7 volts, the nominal voltage of our battery pack, and measure how much power the circuit draws in different phases of operation. Here, for example, you can see the spiky power consumption involved when we connect to WiFi and download the time from Adafruit IO:
![Screen_Shot_2022-12-11_at_3.27.18_AM.png](https://cdn-learn.adafruit.com/user_assets/assets/000/000/051/large1024/Screen_Shot_2022-12-11_at_3.27.18_AM.png?1670750886)
We're only in this mode briefly, when the ESP32-S2 first turns on, so it's not that important of a number. There are three more important numbers:
- Current consumption with the lights off (standby)
- Current consumption with the lights on (active)
- Current consumption with the lights off, in deep sleep (deep sleep)
Standby Current Consumption
When the ESP32-S2 finishes fetching the time, it's awake, but the lights aren't on yet. In this mode you can press the button to configure the tree. Let's measure that current consumption over a ten-second period:
![Screen_Shot_2022-12-11_at_3.31.59_AM.png](https://cdn-learn.adafruit.com/user_assets/assets/000/000/052/large1024/Screen_Shot_2022-12-11_at_3.31.59_AM.png?1670751315)
The answer: about 80 milliamperes. You can napkin math this to get a sense for our standby time in this mode: 4400 milliampere hours divided by 80 milliamperes is about 55 hours, or just over two days in standby.
But then, we don't want the tree in standby. We want it shining bright.
Active Mode Current Consumption
Let's trace the power consumption when the Neopixels are lit and animating:
![Screen_Shot_2022-12-11_at_3.34.06_AM.png](https://cdn-learn.adafruit.com/user_assets/assets/000/000/053/large1024/Screen_Shot_2022-12-11_at_3.34.06_AM.png?1670751378)
Average power consumption varies depending on how many lights are twinkling at once, but it's safe to say these lights are chewing through about 160 milliamperes when lit.
Napkin math again: 4400 milliampere hours divided by 160 milliamperes is 27 hours.
Let's say we want the tree lit for four hours a day. In theory, we could stretch those 27 hours over a week: four hours Monday, four hours Tuesday, etc. But if the Feather is in standby mode in between — consuming 80 milliamperes an hour — it's going to eat up an hour of glowing for every two hours it's in standby.
We'll be lucky if it lasts two days.
Deep Sleep Power Consumption
Now, let's bring deep sleep into the mix. How much current is the Feather consuming in deep sleep?
![Screen_Shot_2022-12-11_at_3.30.00_AM.png](https://cdn-learn.adafruit.com/user_assets/assets/000/000/054/large1024/Screen_Shot_2022-12-11_at_3.30.00_AM.png?1670751446)
The blue line is so low it's barely visible, but you can check the box at the bottom left of the graph: that's barely over one milliampere! That means deep sleep mode consumes one seventieth the power of standby mode.
Of course, it's not in Deep Sleep all the time the lights are off. You'll recall, we wake the device once a minute to update the time. Let's take a look at a one minute long power trace, to get a sense for our average consumption when the lights are off and we're in deep sleep:
![Screen_Shot_2022-12-11_at_3.30.40_AM.png](https://cdn-learn.adafruit.com/user_assets/assets/000/000/055/large1024/Screen_Shot_2022-12-11_at_3.30.40_AM.png?1670751527)
Final answer: about 2.5 milliamperes. We have to wake up for a second or so each minute, but the long nap in between makes up for it.
Napkin math: 4400 milliampere hours / 2.5 milliamperes comes to 1,760 hours, or more than 73 days! Deep sleep means that we no longer have to worry about our current consumption when the lights are off: the number is so low as to not even be a factor. We can put the tree on for an hour a day and expect it to last 27 days, or at four hours a day it should last about a week.
Conclusions
This was a beast of a guide, but we covered a lot of ground!
- We built a functional user interface with one button
- We connected it to a low-power display that can remain on for months on end
- We made a sweet Neopixel animation and made it activate on a schedule
- We implemented deep sleep for all the times it's not active
- We also measured the impact of deep sleep on our gadget's battery life
Deep sleep is a powerful tool for getting the most out of your battery powered gadgets, and CircuitPython makes it easy to take advantage of it. Time alarms let you schedule wakes at regular intervals, and pin alarms let you wake the gadget up when you need it. Finally, sleep memory lets you keep track of aspects of your application's state, even when your script has to start from scratch.
Now go forth, and make battery powered gadgets that stand the test of time!