Raspberry Pi Zero 2 battery runtimes, optimization, and setup

How to run a Raspberry Pi off a battery

The easiest way for a plug-and-play experience is to run it off a power bank made for recharging phones. They’re the easiest because everything works; but they are also the least customizable.

If you want a more customizable solution, consider getting the PowerBoost 1000 Basic which will allow you to step up voltages from 1.8V which means you can use 2x NiMH batteries or one lithium battery to power your Raspberry Pi Zero 2 W.

Examples of battery-powered applications with the Pi Zero 2

Using the Raspberry Pi Zero 2 on a battery makes sense for applications such as,

  • Retro gaming emulation: Retroflag GPi case or a custom build with a 7” screen
  • IoT/automation devices that are far from a power outlet (weather sensor, pollution detector, animal cameras, plant watering devices, pet feeders)
  • ePaper displays: digital name tags, stock tickers, to-do lists

How to log uptime

pi zero 2 with battery pack

In order to log your uptime, you should install the package uptimed.

Open up a Terminal and run:

sudo apt-get install uptimed

After installation, you need to start and run the service by running:

systemctl enable uptimed

then

systemctl start uptimed

Since we’re trying to establish how long of a battery runtime we can expect, it’s important to ensure uptimed’s config files allow much shorter logging intervals than what’s default.

By default, uptimed only writes to the logs every hour, and will not record any records shorter than one hour.

In order to change this, you need to change the config file. By default

In Terminal, run:

sudo nano /etc/uptimed.conf

Change the following variables:

UPDATE_INTERVAL=60

LOG_MINIMUM_UPTIMED = 60

By default, both variables are set to one hour (either 3600 seconds or 1h). By setting them to 60 seconds, we can log the battery’s runtime down to the minute.

Idle Runtime

Runtime: 30 hours 12 minutes

I ran a 5000mA power bank on the Raspberry Pi Zero 2W with no attachments and on the Raspberry Pi OS (2021-10-31). Everything is default.

This represents the best-case battery life that you would get out of a default Raspberry Pi Zero 2 W.

Stress Runtime

In reality, you’re likely to have certain attachments to it such as HDMI or something on the GPIO. So, the next test will be a better way to find out what’s the worst-case scenario.

Runtime: 6 hours 54 minutes

In order to run a stress test, I ran the command

stress-ngcpu 4cpu-method fft

The –cpu-method fft and -cpu 4 were used based on a conclusion on the Raspberry Pi forum, which found that it drew one of the higher loads

I immediately noticed the CPU utilization shooting up to 100% upon executing this command.

Optimizations

You can further reduce power consumption by turning off various components of the Raspberry Pi Zero 2 W.

Here are the power savings you can enable:

Turn off LED: 5mA1

Turn off WiFi: 11mA-187mA2

Use legacy drivers + disable HDMI: 21mA + 17mA 2

Turn off LED

raspberry pi zero 2 led wifi
Before

You can save 5mA by turning off the LED. Here’s how.

If you just want to run it once, you need to run this command in terminal:

echo none | sudo tee /sys/class/leds/led0/trigger

However, if you want the LED to be permanently turned off at reboot, then open up your terminal and type in:

sudo crontab -e

Once you’re in the file, scroll all the way to the bottom and type in these lines:

@reboot echo none | sudo tee /sys/class/leds/led0/trigger &

After your next and subsequent reboots, your Pi Zero 2 W’s green LED will stay lit until it boots the OS up, whereby it’ll be turned off.

Turn off WiFi

By the same token, you can permanently turn off WiFi by running the command

sudo rfkill block wifi

To make this command run on reboot, open up your terminal and type in

sudo crontab -e

Scroll to the bottom and type in this line

@reboot sudo rfkill block wifi &

Once you reboot, you should see that your WiFi is disabled at startup.

raspberry pi zero 2 disable wifi and led turned off
After

Use legacy drivers + disable HDMI

If you have built a battery-powered device, chances are much higher that you won’t be running a monitor.

Or perhaps you plan to run your Raspberry Pi Zero 2 W in headless mode. That’s also another reason to disable HDMI.

The contradictory thing here is that I had to enable WiFi, hence incurring power drain, in order to disable HDMI so that I could control my Pi Zero 2 via SSH. So, choose your battles.

Enable legacy GL drivers

Before you disable HDMI, you will need to use the legacy graphics driver. 

Open up a terminal and run:

sudo raspi-config

Then, go to Advanced Options -> GL Driver -> Legacy

Now that this is done, you can go ahead and disable your HDMI by running the command:

sudo nano /etc/rc.local

Just above the line “exit 0”, type in /usr/bin/tvservice -o

To re-enable HDMI, just delete this line. I did it via SSH.

Disable cores

While all of the tips above reduce idle power consumption, you can also limit the maximum power consumption by disabling cores.

In order to do this, you’d want to open a terminal and type in:

sudo nano /boot/cmdline.txt

Type in maxcpus=1 in the first line and save the file by pressing CTRL + X and saving by pressing Y.

Then, reboot.

Upon reboot, you can check if your modification worked by running lscpu in terminal.

If you see “Off-line CPU(s) list: 1-3”, then it worked and you’re running on one core.

disable cores raspberry pi zero 2 w

If you want to learn more about what you can do with your Raspberry Pi Zero 2, check out this article.

Leave a Comment