https://gist.github.com/JChristensen/10470affa2ec984d4cac7ef70f16b7c2
Jack Christensen
May 2021
I recently purchased a PowerBoost 1000 and a 2500mAh LiPo battery from Adafruit to use as a small uninterruptible power supply (UPS) for a Raspberry Pi.
From a little testing, I could tell that the setup would power a Pi Zero W for quite some time, but I wasn't sure how long. Christopher Barnatt's recent Explaining Computers video inspired me to find out.
I set up a Pi Zero W as a headless machine with the latest version of Raspberry Pi OS Lite (04Mar2021).
Then I wrote a short Bash script to run the uptime
command and append the output to a file on another (mains-powered) Raspberry Pi. By not storing the information on the Pi under test, there is no concern about file corruption when the battery is exhausted:
#!/bin/bash
# Log uptime to another machine.
# J.Christensen 03May2021
dest="pi3" # destination hostname
logfile="/home/jack/$(hostname)-uptime.log"
uptime | ssh -4 $dest "cat >>$logfile"
Next, I scheduled the script to run every five minutes with cron. Here is the crontab entry (from crontab -l
):
# m h dom mon dow command
*/5 * * * * /home/jack/uptime.sh
Finally, I made sure the battery was completely charged, disconnected the PowerBoost 1000 from the mains, rebooted the Pi Zero W, and let it run.
The Pi ran considerably longer than I expected, over 25 hours. Here is the end of the log file:
22:30:01 up 1 day, 1:28, 0 users, load average: 0.10, 0.11, 0.09
22:35:01 up 1 day, 1:33, 0 users, load average: 0.20, 0.16, 0.11
22:40:01 up 1 day, 1:38, 0 users, load average: 0.10, 0.12, 0.09
22:45:01 up 1 day, 1:43, 0 users, load average: 0.09, 0.10, 0.09
This is no doubt a best-case scenario as the Pi Zero W was essentially doing nothing. Also it was fairly close to my router so it was probably not expending a lot of power for the wifi connection. Depending on workload and whether the Pi is powering other peripherals (camera, USB stick, etc.), the battery run time could be significantly reduced. When idling, I measured the Pi Zero W current draw at about 80mA.