Raspberry PI UPS

From Electriki
Jump to: navigation, search

UPS for Raspberry PI


If you have a Raspberry PI running as a server, or just like it to keep running during power-outs/burn-outs, you will need some kind of battery backup.

Now the easy solution would be to just plug in the mains adapter into a ordinary UPS, if you already have such a device keeping other hardware safe, all good, but if not this would not be an ideal thing to do. The Raspberry PI use very little power, less than 5 W. an UPS will quite easy use that in idle, thus double your costs of running it.

I know, I know, 5 W 24x7 is 43.8 kWh / year, depending on prices around the world, it is about one visit to Burger King with side-orders. but still, why should it cost 2 times that? :)


If not doing the backup on mains, but directly on the 5 V USB, we will save quite a lot (relatively..) on switching losses from mains -> 5 Vdc

One approach would be to just whip up some batteries, a charger circuit and interface circuit to the USB input on Raspberry PI, a so-called on-the-line UPS.

This means that the mains->USB charger is connected to your battery-bank that in turn is connected to the Raspberry PI. When mains goes away, the batteries will keep everything running.

Losses is of course still a "problem" but they can be made to be much less, it will be whatever your interface circuit needs to operate and regulate a 5 Vdc output and what your charger circuit needs to keep the batteries charged ( Trickle-charge(TM) ).

Searching for ideas for the circuits, I stumbled upon this beauty: The Romoss Sofun 1 - this device is meant as a on-the-road extra battery pack for your phone, MP3-player, tablet or other device that runs of 5 Vdc. Found one on E-bay for 6.29 UKP. not bad, assuming batteries are not made of wet cardboard and vinegar.

After only 10 days, the package was in my hands, lets connect this baby up! the connectors even fit directly, unplug charger from Raspberry PI, connect that to Sofun, connect cable that came with sofun from sofun to Raspberry PI, how easy.


Surely, I was naive to think this would go so easy. And yes, there was a problem:

When disconnecting the USB cable from charger to simulate a power-loss, the sofun takes a few mSec to switch over to batteries, enough for the Raspberry pi to reboot due to low voltage...

Right boys and gals! its electronics time!

First up: measure the drop-out time and how long the Raspberry PI can run of the on-board 220 uF on the 5 V rail.

As we can see, the 220 uF starts to discharge quickly for 1.4 mSec ( X-division 1.5 to 2.2 with 2 mSec/div ). after that it discharge slower. This is an indication of the lowest voltage the Raspberry PI will operate on, once we go below this limit she switch off and the power-consumption drops hence the slower discharge.

Moving on, we can see the Sofun 1 is providing power after 7 mSec ( X-division 1.5 to 5.0 with 2 mSec/div ). This is the time we need to take care of business ourself, by increasing the on-board capacitor.

As the load remains the same no matter the capacity, we can simply extrapolate:

7 mSec / 1.4 mSec = 5 times MOAR capacity is need, we have 220 uF, we need a total of 1100 uF, an extra 880 uF.

Adding a 1k uF // to the 220 uF did the trick, Raspberry PI now continues to operate when mains is disconnected, the voltage drops to 3.7 V, still enough to keep things running but a USB device will likely not find it funny, but just to be safe, lets add another 1k uF, to a total of 2220 uF. This time the voltage drops to 4.1 - 4.2 V, that's OK, not USB-power specs OK, but hey, nobody is perfect. Problem solved(tm).


How long will this keep running on batteries? Glad you ask, its Tau-time!

220 uF gives us 1.4 mseconds from fully charged ( 4.7 Vdc ) to 3.3 V, a discharge of ( 3.3 / 4.7 ) 29.8%.

29.8% => e(1-0.298 ) = 0.35 Tau

1.4 mSec = 0.35 Tau, thus 1 Tau = 4.0 mSec

Tau = R x C, rewrite to R = Tau / C

R = 4 mSec / 220 uF = 18.2 Ohm

4.7 V / 18.2 Ohm = 258 mA, in practice this is a bit low, the rated current for the Raspberry PI model B is 700 mA.

With a current-consumption of 258 mA continuously, the 2600 mA battery-pack will last just over 10 hours, minus losses in the electronics inside it, and the state of the batteries.

Now, surely we need to measure the actual backup time, rather than relying on china-specs of batteries and potentially faulty calculations based on very short-time observations. Fear not young reader, as of writing this, Goofy is doing the measurements, in his own way:

A script writing $date to a file, is run every minute by Cron, when the battery-pack gives up, I will let it sit for 10-15 min or more, power it up and look at the file, the last time-stamp with 1 min. intervals was the last to be recorded before shutting down.

Its simple, its Goofy and probably not the way most of you would have done it, but in the process of this I wrote my first scrip in Linux ever :-)

adhoc measurements

Raspberry PI in idle, mouse+keyboard connected. running on battery from 14:32 to 17:49 = 3 hours and 17 minutes. with 2600 mAh, this comes to 792 mA of continuous current.

Raspberry PI in idle, NO mouse or keyboard, only LAN connected. running on battery from 01:19 to 04:12 but at the same time going away from DST, so +1h. a total of 3 hours and 53 min resulting in 669.5 mA.

Most pages I've found report much lower current consumption of the Raspberry PI in idle, around 300-500 mA, my calculation of 258 mA is a bit off, but so may the 2.6 mAh be, who knows.. but we should measure this for ouself, yes we should.

Real measurements

Measurements to be done:

Current consumption of the Raspberry PI in idle ( as it will be most of the time )

mAh of the Sofun 1 battery-pack at a discharge current similar to above.

mAh of the Sofun 1 battery-pack at 1 Adc load.

More to come as we discharge...

Not going to happen, as of writing this ( 2014-03-30 ) the PI have been running for 82 days and will continue to do so, measuring pulses from electric meter 24x7.

We need more Capacity, Scotty!

So, in December 2015, mains dropped out quite a few times, for reasons unknown, I wasn't cooking.

The backup worked, somewhat, in the sense that the LAN ( on on-board USB I believe ) fails, somebody did mention the current voltage drop is not completely kosher with regards to USB, and said person was right. Now, an extra 4200 uF has been added, lo and behold, the LAN keeps working, as does the HDMI output witch I found also died in December.

We can now conclude this project to be done as of 2016-01-10 :-)