paulv
Posts: 563
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Yet another Pi Power Supply with UPS

Wed Feb 04, 2015 10:43 pm

We all know by now (should know) that a reliable and solid 5V supply is critical for the Pi. Especially if you use the earlier non + versions without the improved USB power. Many WIFI USB adapter problems can be solved by a good and solid supply.
Also, if the power has brown-outs during write operations to the SD card, it can become corrupted.

Here is a very simple supply that covers these requirements.

First of all, most wall-warts have difficulty supplying 5V to the Pi at 500mA or more. This is either due to the design of the wall-wart if it was designed to charge your phone or tablet, or there is a significant voltage drop from the wall-wart to the Pi through the cable. You’ll be surprised how thin the actual conductors are in most cables. The best way to see if the Pi gets the full power it needs is to make sure you measure 5.0V between TP1 and TP2 on the Pi circuit board.

One simple way to make sure the Pi gets what it needs is to use a DC-DC step-up convertor, and adjust the output such that the voltage between TP1 and TP2 is indeed 5V0. These convertors can be had for less than $10 on eBay or Amazon.
The simple, albeit somewhat destructive method is, to cut your wall-wart cable to the micro USB plug, and put the step-up convertor in the middle. This preserves the mico USB input to the Pi, and keeps everything else the same.

If you decide to power the Pi through the GPIO connector, you need to supply a (resetable) fuse and if possible a transient suppressor, because that is what you’ll be bypassing.

To add back-up power to the Pi so it can survive brown-outs of the mains, you can rather easily add a battery. If you restrict the battery to non-rechargeable 1.5V AA cells, you’ll need 3 (not more!) of those and two Schottky Diodes to combine the two supplies. In that case, you must eliminate D1 and R3 !

If you use 1.2V NiMH or NiCAD’s you can also add a simple trickle charger to maintain the charge. This only takes two more parts (D1 and R3), and the following diagram shows how to do that for 3 cells. [Edit] Three cells is the maximum, because we will need about 1.4 Volt per cell to charge them. If you use 3 cells in a 4 cell battery holder, you can bridge the empty space with a wire.
Unless you know what you're doing, I suggest that you stay away from Lithium-Ion batteries, because the charging of those is non-trivial and potentially dangerous. They can explode if mishandled.

The concept of the circuit relies on the fact that the wall-wart will normally supply the power to the Pi, through the step-up convertor. If there is a brown-out, the batteries will take over through the Schottky diode OR circuit ( D2 and D3) and that allows you to run the Pi until the cells deplete below the threshold for the step-up convertor, which is somewhere between 2.8 and 3.0V.

If you would like to shutdown your Pi to preserve the SD card after a certain amount of time, you need the circuit of R1, R2 and C1 (10uF is maximum) to tell the Pi that the mains is gone. Your program can put the Pi in the Halt state whenever you want (after a delay) by issuing a sudo halt or sudo shutdown. There are many examples available on this forum. With fully charged cells, the UPS can power the Pi for a few hours. Note that it can take at least 30 seconds for the Pi to reach the Halt state.

If/when the power comes back after you issued the shutdown, you’ll have to restart the Pi manually to let it reboot from the Halt state. This will be an abbreviated boot process. Making this restarting fool-proof and fully automatic is not trivial, I suggest you look at some of my other postings on this forum to see an example on how to do that.
Simple Pi Supply with UPS-C.gif
For 5V DC Wallwart
Simple Pi Supply with UPS-C.gif (30.94 KiB) Viewed 1977 times
Enjoy!
Paulv
Last edited by paulv on Thu Feb 12, 2015 4:18 pm, edited 2 times in total.

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Yet another Pi Power Supply with UPS

Thu Feb 05, 2015 7:07 pm

paulv wrote:...If/when the power comes back after you issued the shutdown, you’ll have to restart the Pi manually to let it reboot from the Halt state....
There appears to be a lack of good, solid, hardware information on this forum. So I'd like to thank you for sharing this with us.

I'm just getting into Picaxe, which are cheap programable devices. If you added an 08m2, you could monitor the voltage across C1 and automatically restart the Pi after the power returns and stabilises (say after 10 seconds).

I'm using a Picaxe in this seasons bird box (http://captainbodgit.blogspot.co.uk/201 ... tails.html). I just wish I'd used one of the adc inputs to measure battery voltage...maybe next year.

hippy
Posts: 7728
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Yet another Pi Power Supply with UPS

Thu Feb 05, 2015 7:42 pm

SteveDee wrote:I'm using a Picaxe in this seasons bird box (http://captainbodgit.blogspot.co.uk/201 ... tails.html). I just wish I'd used one of the adc inputs to measure battery voltage...maybe next year.
From your circuit diagram, it looks like you could move your activity signal from leg 6 ( I/O Pin 1 ) to leg 4 ( Input Pin 3 ). That would free-up leg 6 to be used for ADC input.

paulv
Posts: 563
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Yet another Pi Power Supply with UPS

Thu Feb 05, 2015 7:45 pm

If you're interested, have a look at this post, it deals with a more elaborate Pi supply and more bells and whistles to handle the battery charge depletion.
http://www.raspberrypi.org/forums/viewt ... 11#p606511

And this (long) post deals with a really robust embedded and remote application with a fully automatic boot/reboot function. This has been running for almost 2 years now.
http://www.raspberrypi.org/forums/viewt ... 88#p435088

Enjoy,

Paul
Last edited by paulv on Thu Feb 05, 2015 10:02 pm, edited 1 time in total.

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Yet another Pi Power Supply with UPS

Thu Feb 05, 2015 9:24 pm

hippy wrote:...That would free-up leg 6 to be used for ADC input.
Yeah, there are 6 useful pins on the 08m2, so that would leave me the final pin to signal (low/high) to the Pi that the low battery limit had been reached.

Alternatively I could transmit the measured voltage to the Pi using the pin for serial date, and let the Pi program decide when to shutdown. ...so many interesting things to do, but not enough time right now.

paulv
Posts: 563
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Yet another Pi Power Supply with UPS

Sat Feb 07, 2015 4:11 pm

Here is another supply, based on the same principle.but now using a 12V DC wallwart.
Many of you will have one of these lying around, they typically come with routers or modems, and they typically are capable of 2-3 Amps.

I have already described such a supply, although a bit more complicated because it has a sensor for the battery depletion. Have a look here: http://www.raspberrypi.org/forums/viewt ... 11#p606511

With the advent of cheap (around $10) DC-DC up and down convertors, such a supply can be made more simple. Here is a picture of such a device:
Pic DC-DC up-down.gif
Pic DC-DC up-down.gif (53.02 KiB) Viewed 2568 times


The specifications are impressive:
Input 3.5-28V (mine still worked at 2.8V)
Output 1.25-26V Adjustable
1Amp without cooling, 3Amp with.
These convertors are based on a combination of the LM2596S and the LM2577S chips. Ideal for the following supply:
Simple Pi Supply with UPS-B.gif
For 12V DC Wallwart
Simple Pi Supply with UPS-B.gif (33.23 KiB) Viewed 1977 times
With the explanations in the first post, this should be relatively easy. Note that the R2 and R3 resistors will get warm at 1/2 Watt. You can select a higher wattage if you want, or put more R's in parallel.

[Edit]
If you need to supply more than 1 Amp to the Pi, you need to add cooling to the LM2596S and the LM2577S and change the fuses accordingly.

Have fun,

Paul

[EDIT2] To avoid potential disasters by users that are not engineers, I have modified the schematic, and annotated it better.
Last edited by paulv on Thu Feb 12, 2015 7:44 pm, edited 6 times in total.

User avatar
davidcoton
Posts: 5026
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Yet another Pi Power Supply with UPS

Sat Feb 07, 2015 5:32 pm

Er, isn't that connection to the GPIO for loss of mains going to put tthe input voltage (nominally 12V on to the Pi? Not a good idea, even if R4 prevents damage.
Signature retired

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Yet another Pi Power Supply with UPS

Sat Feb 07, 2015 6:41 pm

davidcoton wrote:Er, isn't that connection to the GPIO for loss of mains going to put tthe input voltage (nominally 12V on to the Pi? Not a good idea, even if R4 prevents damage.
The potential divider (56k & 27K) gives a voltage to the GPIO pin of no more than 3.9Volts. So not a problem.

paulv
Posts: 563
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Yet another Pi Power Supply with UPS

Sat Feb 07, 2015 7:10 pm

David, I made an error with the calculations for these two resisters, after I took a protective 3.3V Zener away from the Pi input. My bad.
Change the 56K to 82K and that will give you 2.9 V. That gives you some head-room if the supply is a little above 12V.

Thanks for pointing this out, I will change the schematic and update the original.

Paul

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Yet another Pi Power Supply with UPS

Sat Feb 07, 2015 7:40 pm

paulv wrote:David, I made an error with the calculations for these two resisters, after I took a protective 3.3V Zener away from the Pi input.
Even if the 12V supply is 10% high (13.2V) with 56k & 27K the voltage is only 4.3V. Still not a problem.

If the supply is likely to be >10% high, maybe you need to put the zener back!

User avatar
davidcoton
Posts: 5026
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Yet another Pi Power Supply with UPS

Sat Feb 07, 2015 8:14 pm

SteveDee wrote:
paulv wrote:David, I made an error with the calculations for these two resisters, after I took a protective 3.3V Zener away from the Pi input.
Even if the 12V supply is 10% high (13.2V) with 56k & 27K the voltage is only 4.3V. Still not a problem.

If the supply is likely to be >10% high, maybe you need to put the zener back!
Yes it is -- the Pi GPIO runs at 3V3 not 5V, so you are relying on the resistor to limit current and the input protection diode. Not a good idea. And the voltage converter is specified to a much higher voltage (up to 28V), although the circuit given does specify 12V.

I had missed the effect of the divider! But even so, I think I would want a zener to clamp the voltage
Signature retired

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Yet another Pi Power Supply with UPS

Sat Feb 07, 2015 9:24 pm

davidcoton wrote:...the Pi GPIO runs at 3V3 not 5V, so you are relying on the resistor to limit current and the input protection diode...
Just because the GPIO runs from a 3.3V supply, it doesn't mean the input is limited to 3.3V. And how do you know that the chip has an input protection diode? The chip details are not in the public domain.

If this design is to be used with a suspect 12V supply, then it probably needs a zener. Otherwise I'd remove R5 & C2 and choose a high value for R4 (to limit the gpio input current to about 60uA). I'd then poll the input every (say) 5 seconds and look for (say) 3 consecutive lows in a row in order to determine power down.

The general advice that you should not put high voltages from low impedance sources on the gpio pins is reasonable, as most people on this forum do not have a strong background in electronics.

paulv
Posts: 563
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Yet another Pi Power Supply with UPS

Sat Feb 07, 2015 9:47 pm

SteveDee,

Here is a schematic of one of the GPIO Ports.
GPIO-Pin.gif
GPIO-Pin.gif (7.62 KiB) Viewed 2377 times
It does show the clamping diode to GND.
[EDIT]
The above diagram floats on the internet, but is not correct. It seems that there is no clamping diode between the input and the 3V3 supply. What seems to be there instead is a diode connected to the 5V supply. That makes the GPIO port 5V "tolerant". Read below about what SteveD found out.

This means that you could safely connect 5V logic to the ports. Make sure however that you limit the current, which is the real Pi killer. Use a 1K resistor in series with the Ports, to limit the current going in to the Pi to 5mA, which should be safe.

Have fun!

Paul
Last edited by paulv on Fri Mar 13, 2015 7:12 pm, edited 3 times in total.

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Yet another Pi Power Supply with UPS

Sun Feb 08, 2015 8:08 am

paulv wrote:...It does show the clamping diodes to 3V3 and GND....
Hi Paul,
Yes, I've seen that schematic before. It is described as an "equivalent" circuit, and is a very good general illustration for how the i/o might look.

But of course it is a simplification. If there really were just a diode between the i/o and 3.3V you would expect the input current to rise rapidly as the input voltage rose above 3.3V plus the diode conduction voltage. But this doesn't seem to happen for input voltages up to 4.7Volts.

You may like to take a look at my notes for a simple set of measurements using 5V and a range of limiting resistors.(http://captainbodgit.blogspot.co.uk/201 ... evels.html )

If I get some time this week, I may repeat this test using 12V, as I'm sure there is input protection, but suspect it doesn't kick in below 5V.

Let me also repeat to others reading this, that it is generally a bad idea to abuse the gpio. It is high i/o current that will burn your Pi. High i/o current may be caused by allowing too much current to flow into the input or drawing too much from the output.

This forum (and the Pi in general) is used by people of all abilities and ages, from primary school age to the "are you still here?" age like me. So stick to the general gpio guidelines unless you know what you are getting into.

Have fun, stay safe!

paulv
Posts: 563
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Yet another Pi Power Supply with UPS

Sun Feb 08, 2015 3:06 pm

Hi SteveDee,

Your crusade for the safe connections to the GPIO-Ports are well taken.
Also your point about non-engineers using proposed circuits on this forum are also valid.
I will make sure that in the future I will be more careful, just in case.
In this light, I have modified and annotated the schematic above, because of the potential lethal voltages (for the Pi) when you are working with supplies above 5 Volt.

Thank you for the inputs,
Paul

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Yet another Pi Power Supply with UPS

Wed Feb 11, 2015 1:21 pm

SteveDee wrote:...If I get some time this week, I may repeat this test using 12V, as I'm sure there is input protection, but suspect it doesn't kick in below 5V....
I have now repeated the tests with a 12 Volt source, taking the GPIO input to over 6 Volts.
GPIO input VI graph.png
GPIO input VI graph.png (23.43 KiB) Viewed 2119 times
Please read my blog post (including todays edit) in order to understand the context of these tests:-
http://captainbodgit.blogspot.co.uk/201 ... evels.html

paulv
Posts: 563
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Yet another Pi Power Supply with UPS

Wed Feb 11, 2015 1:31 pm

Hi Steve,

Well done. This confirms that the GPIO Ports are most likely indeed 5 Volt tolerant.
I still think that you still need to be careful, and adding a 1K resistor in series with the GPIO Ports will limit the current (the real killer) to a maximum of 5mA, and that should be considered safe.

Paul

User avatar
SteveDee
Posts: 343
Joined: Thu Dec 29, 2011 2:18 pm
Location: Sunny Southern England
Contact: Website

Re: Yet another Pi Power Supply with UPS

Wed Feb 11, 2015 1:45 pm

paulv wrote:...I still think that you still need to be careful, and adding a 1K resistor in series with the GPIO Ports will limit the current (the real killer) to a maximum of 5mA....

Paul
I agree

Return to “General discussion”