emma1997
Posts: 868
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Poor Man's Pi Safe Backup Supply (UPS)

Tue Jul 28, 2020 7:10 pm

This DIY circuit senses when main power is removed and then goes into safe shutdown. It eliminated the risk of corrupting SD and other drives if just cutting power. It has few components so easy to build and parts just cost a dollar or two.

The battery only has to keep Pi running for a few seconds so just about any 18650, AA, or even AAA cells can be used. At least couple lithium type or half dozen NIMH or Alkaline to feed the converter. You could also use a 12v security system or car battery for longer term runs.

Two diodes select the higher of the two DC sources for uninterrupted service. A simple resistor divider signals the Pi via GPIO3 to do a safe shutdown when main DC goes away. It reboots the OS automatically when power comes back on.

No special software or programming are needed. Just add the following line to /boot/config.txt:

Code: Select all

dtoverlay=gpio-shutdown,gpio_pin=3,active_low=1,gpio_pull=up
I did this a while back for myself and couple friends. There are lots of requests for safe backups on this forum too (four in the last 24hrs alone) so thought it might help others to put it up here. Attached are schematic and a photo ready to be hooked up to a Pi. As can be seen it simply goes inline between Pi and main supply. This has been tested with Pi4 and Pi2 running Buster but may work with other models and OS too.
Attachments
SAFE_SCHEM_v1.0.JPG
SAFE_SCHEM_v1.0.JPG (31.03 KiB) Viewed 1569 times
SAFE_3871.JPG
SAFE_3871.JPG (128.45 KiB) Viewed 1569 times

pidd
Posts: 721
Joined: Fri May 29, 2020 8:29 pm
Location: Birkenhead, Wirral, UK
Contact: Website

Re: Poor Man's Pi Safe Backup Supply (UPS)

Tue Jul 28, 2020 9:16 pm

The 1N5817 are only 1A so you are sailing a bit close to the wind, I'd use a 1N5820 for plenty of reserve.

emma1997
Posts: 868
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pi Safe Backup Supply (UPS)

Wed Jul 29, 2020 3:13 pm

Definitely an interesting point and I've spent many hours pondering it. There may be some advantage to using higher current parts but in this case other factors involved:

First and foremost, being a 'Poor Man's' project the cost is a major factor. 1n5817 is a generic part common on the wold market and runs about a penny ea in small quantity. Others with similar or better specs may be 10x or even 100x pricier and much harder to find. This one I use does have significant safety margin in this application yet by far most economical.

Also note these diodes are on the 12v side which has almost 1/3 the current used on the Pi end. I monitor and log draw on most of my Pi and find it's more like milliamps than amps. Even Pi4 as indicated in other threads. Using 24v or 36v input relaxes the requirement even more so this cheapie diode seems to do ok here.

IME long time ago as semiconductor product engineer I determined datasheet specs are not always the major consideration. Mostly for CYA purpose I think. Heat is the real enemy. This is true not only of semi, but also batteries ,resistors, caps, inductors, and many other types of components. 1n5817-19 family is quite different process from 1n5820-22 and most other diodes in having lowest typical Vf drop of all. This drop is what actually limits current and as long as I can feel no heat at all I'm happy. "Let Your Fingers Do the Talking"

There's other projects (EV) requiring very high amps where 1n5817 and even 1n5820 have no chance. When that becomes a consideration my goto products are the 10sq045-20sq045 line. They are another of those 'generic' parts that are very common overseas easily available and cost a tiny fraction of what more exotic schottky go for. Not much more than the 1n5817 yet very thick leads and huge package capable of 10x-20x more power.

So you are right that having more current margin is often better but if that becomes an issue I really like those hefty 'SQ' series parts. Specially 15 amp version which currently (lol) has best cost/benefit ratio.

pidd
Posts: 721
Joined: Fri May 29, 2020 8:29 pm
Location: Birkenhead, Wirral, UK
Contact: Website

Re: Poor Man's Pi Safe Backup Supply (UPS)

Wed Jul 29, 2020 4:06 pm

emma1997 wrote:
Wed Jul 29, 2020 3:13 pm
Also note these diodes are on the 12v side which has almost 1/3 the current used on the Pi end. I monitor and log draw on most of my Pi and find it's more like milliamps than amps. Even Pi4 as indicated in other threads. Using 24v or 36v input relaxes the requirement even more so this cheapie diode seems to do ok here.
Yes, but when it switched to battery it can go down to around 7V or less which the corresponding increase in current and there's also the converter losses to take into account.

The whole concept of a UPS is to improve reliability, it doesn't make sense to have it running too close to any limit. I'm sure there are some higher current schottky diodes available for pennies, I just happened to have some 1N5822 floating around and knew the lower forward voltage version was the 1N5820 which will improve reliability (diode will have a lower junction temperature) - the original choice of 1N5817 was also the lower forward voltage type.

"milliamps" is a bit misleading, I'd settle for "hundreds of milliamps" ;)

lurk101
Posts: 86
Joined: Mon Jan 27, 2020 2:35 pm

Re: Poor Man's Pi Safe Backup Supply (UPS)

Wed Jul 29, 2020 4:58 pm

Assuming a .4V voltage drop across the diode and about 80% efficiency at the DC to DC converter, you're pretty close to a 1 to 1 ratio between the current drawn from the batteries and the current to the Pi.
A thorough IPV6 connectivity test https://ipv6-test.com

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

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 9:06 am

With respect to the circuit posted; what's to stop the batteries being run down to below their safe to recharge levels ?

achrn
Posts: 422
Joined: Wed Feb 13, 2013 1:22 pm

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 10:47 am

I'd add a resistor and a diode and trickle recharge the batteries all the time the power is on.
See http://www.astounding.org.uk/ian/raspi-ups/index.html.

I posted that circuit to these forums some years ago, and even then it was pointed out that someone else had done it before me. The dtoverlay addition is useful, thanks.

pidd
Posts: 721
Joined: Fri May 29, 2020 8:29 pm
Location: Birkenhead, Wirral, UK
Contact: Website

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 11:33 am

achrn wrote:
Thu Jul 30, 2020 10:47 am
I'd add a resistor and a diode and trickle recharge the batteries all the time the power is on.
You should never do that with lithium batteries, it can cost you your house and family.

Its not just that the target voltage is damaging because its way above the fully charged voltage, even if you limit it to the fully charged voltage with a zener or something, maintaining the battery at its fully charged, on-charge voltage is damaging as well.

If they are only charged to their 80% charge it is thought this is safe(r), however that isn't at a fixed voltage, it is very temperature dependent and you need a temperature sensor with compensation to do this.

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

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 1:01 pm

pidd wrote:
Thu Jul 30, 2020 11:33 am
achrn wrote:
Thu Jul 30, 2020 10:47 am
I'd add a resistor and a diode and trickle recharge the batteries all the time the power is on.
You should never do that with lithium batteries, it can cost you your house and family
Indeed. While one can build a cheap battery backup using non-rechargeables, or SLA or other rechargeables which can be run dry or float charged, it soon becomes clear that there's little to be gained over those Pi UPS products which already exist and have been designed to do the job properly and safely.

A useful, non-fallible, "poor man's UPS for a Pi" isn't really achievable. I think most people who head down that route with high hopes come to that conclusion.

User avatar
diogen151
Posts: 67
Joined: Mon Apr 04, 2016 8:32 am
Location: Agram

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 1:39 pm

The device in the diagram does exactly what it is intended for: shutdown delay if the 12V power supply fails and the signal that the main power supply has failed.
And something that is not a problem in this case, in the second picture, the 18650 battery has a declared capacity of 5.3 Ah, which is volumetrically impossible for the 18650 type.
This is not a problem here, but if someone would perform a UPS with the desired longer power supply with 18650 at best it goes up to 3.4 Ah (e.g. panasonoic NCR 18650B).
Šalica malina.

Heater
Posts: 16092
Joined: Tue Jul 17, 2012 3:02 pm

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 4:32 pm

achrn wrote:
Thu Jul 30, 2020 10:47 am
I'd add a resistor and a diode and trickle recharge the batteries all the time the power is on.
Do not do that.

I'm no battery expert but from what I read here and elsewhere this is a very bad idea:
https://batteryuniversity.com/learn/art ... e%20charge.

Quote:
It is difficult, if not impossible, to slow charge a NiMH battery. At a C rate of 0.1C to 0.3C, the voltage and temperature profiles do not exhibit defined characteristics to trigger full-charge detection, and the charger must depend on a timer. Harmful overcharge can occur when charging partially or fully charged batteries, even if the battery remains cold.
So at a minimum you damage your batteries and the circuit does not function at some point in the future when you need it to.

I'm not sure what the risk of these things catching fire or whatever but I would be very wary of that as well.

<anecdote>
Back in the mid 1970's my friend built a digital clock with TTL logic chips. He wanted it to keep time in power cuts so he fitted it out with NiCad batteries and a simple trickle charging circuit as in the diagram presented by achrn. He gave it to his mother as a present.

His mother was frightened witless when the thing exploded after some weeks or months.

I know, that is old NiCads, I would still be wary though.
</anecdote>
Memory in C++ is a leaky abstraction .

dustnbone
Posts: 308
Joined: Tue Nov 05, 2019 2:49 am

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 4:56 pm

Protection for the 18650s is pretty easy and cheap to implement.

https://www.ebay.ca/itm/2S-8A-7-4V-8-4V ... 2863547887

Something like that will provide low voltage cutoff during discharge and high voltage cutoff and cell balancing during charging.

As noted above, the cells pictured in the photo are not 5.4Ah, as the highest density 18650 cells are around 3.5Ah. They're fake and I personally wouldn't trust them.

Most likely they are just much lower capacity than advertised, and otherwise fine, but "not fine" with an 18650 cell is very bad.

emma1997
Posts: 868
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 5:18 pm

A simple high value resistor can be used with Nixx and even non-rechargeable type to offset self discharge. However calculating the correct value is tricky. Good news is even if you are in the ballpark it can extend shelf life by one or two orders of magnitude. I've used this trick in both hobby and commercial designs with great success getting 10 years instead of a few months out of both non-LSD NiMh and Zinc. BTW we are talking microamps here.

With a somewhat lower resistance or other slightly higher current limit it's possible to trickle charge Nixx because they are quite resistant to overcharge damage. With low current they can take a lot of abuse. Higher currents not so easy but even then the risk is minimal with small chance of boiling off electrolyte at milliamp level.

In fact most cheap AA/AAA chargers do not use the proper delta-v method but merely limit current. The cells may get warm and have shorter cycle life but this minimized by no more than overnight use. Higher end units sense the small voltage drop as cells start to heat up when full and then turn off.

None of these a good idea at all for lithium types due to the risk of ballooning and venting. Explosion and fire is much less likely but why risk burning your house down when proper CC/CV charging costs only a few cents more. I've been using the circuit below for many years now for various projects with no issues. With that particular diode pair it does not bring them up to full SOC but definitely enough to keep the Pi running for the few seconds it takes to shutdown safely.

I did not include this in the first post because most of the guys here use primary cells and it just complicates things. I suppose if mains outages were a constant threat then rechargeable are a must and a charge circuit is more convenient. The more often it happens the smaller the resistor value needed..The 2k is calculated for couple shutdowns a year tops. Most people are not plagued by this and only need emergency backup so alkaline or charging offline is simpler.
Attachments
SAFE_SCHEM_v1.1.JPG
SAFE_SCHEM_v1.1.JPG (37.12 KiB) Viewed 1040 times
Last edited by emma1997 on Thu Jul 30, 2020 5:41 pm, edited 1 time in total.

dustnbone
Posts: 308
Joined: Tue Nov 05, 2019 2:49 am

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 5:41 pm

For LiIon cells, the most important thing is they don't exceed 4.2V per cell, and for the sake of longevity it's best if they don't spend too much time above 4.0V.

On the low end, 2.5V is about as low as they should go, and again they are best off not spending too much time at that level. 3.6-3.8V is considered ideal storage voltage, corresponding to about 50% SOC.

emma1997
Posts: 868
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 5:52 pm

Sorta. There is mass hysteria on the internet over never letting them ever hit the top or bottom even for a fraction of a second. Truth is a short time in either state does little harm.The longer you leave them there the more impact. Worth noting that it has less effect on actual capacity as most claim but generally internal resistance suffers more. Low draw applications would notice little or no degradation even severely abused like this.

By far the biggest danger to most chemistries is temperature. Things go bad very quickly when hot. A related myth is car batteries are damaged by storing on a cold cement floor when actually the opposite is true. It's true that current output suffers when cold but capacity and Ir are actually extended. Current capability recovers quickly when brought back up to temperature.

BTW while 3.8v is not too far below half for our common cobalt type , 3.6v is almost empty. That myth got started back in the Battery University days and perpetrated for decades in charts and tales of woe ever since. Those of use who use EV for transportation and monitor temp and hundredth of a volt know the real story. No fun having to walk home on a sweltering summer day.

pidd
Posts: 721
Joined: Fri May 29, 2020 8:29 pm
Location: Birkenhead, Wirral, UK
Contact: Website

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 7:43 pm

emma1997 wrote:
Thu Jul 30, 2020 5:52 pm
A related myth is car batteries are damaged by storing on a cold cement floor when actually the opposite is true. It's true that current output suffers when cold but capacity and Ir are actually extended. Current capability recovers quickly when brought back up to temperature.
Yes a bit of a myth, its not so much about the cold floor, its the fact its been left lying around to go flat. A fairly flat car battery will freeze and never recover properly, a fully charged lead acid is almost impossible to freeze (ok, our Alaskan and Russian friends etc may disagree with that).

The physical design of car batteries makes them very sensitive to deep discharge, basic lead acid design is pretty impervious chemically and can even be reverse-polarised.

[rest of soapbox deleted]

emma1997
Posts: 868
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 8:04 pm

Totally. I recall once while working on ore ships in Duluth,MN where 30 below freezing and 14' snow banks were common, came out of the motel to find the starter solenoid not even clicking. I popped the tops to see if they needed water and surprised to find a skating rink. Lucky there was a Sears nearby.

Believe it or not car batteries lose capacity with ANY discharge at all. Most designed for couple percent down and no more. Those who crank and crank and crank to get a bad engine going might as well just go out and buy a new battery every time. Also true of deep discharge, marine, hybrid, AGL, etc but not so much due to thicker plates and improved chemistry.

Probably not an issue with Pi. I do still have one running off same lead acid for some years now. Like Energizer Bunny keeps going and going. But being laziest person on the planet, probably won't swap it out til it actually quits.

achrn
Posts: 422
Joined: Wed Feb 13, 2013 1:22 pm

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 9:27 pm

Heater wrote:
Thu Jul 30, 2020 4:32 pm
achrn wrote:
Thu Jul 30, 2020 10:47 am
I'd add a resistor and a diode and trickle recharge the batteries all the time the power is on.
Do not do that.

I'm no battery expert but from what I read here and elsewhere this is a very bad idea:
https://batteryuniversity.com/learn/art ... e%20charge.

Quote:
It is difficult, if not impossible, to slow charge a NiMH battery. At a C rate of 0.1C to 0.3C, the voltage and temperature profiles do not exhibit defined characteristics to trigger full-charge detection, and the charger must depend on a timer. Harmful overcharge can occur when charging partially or fully charged batteries, even if the battery remains cold.
So at a minimum you damage your batteries and the circuit does not function at some point in the future when you need it to.
Well, don't tell the ones that have been doing that job for years in my shed, and maybe they won't realise they shouldn't be working.

Actually, the quote you've quoted is saying you won't trigger charge detection, so will carry on charging forever. As I note on my write-up, the design is such that charging forever isn't a problem.

I agree you shoudln't do it to LiPos (or similar / related chemistries).

Heater
Posts: 16092
Joined: Tue Jul 17, 2012 3:02 pm

Re: Poor Man's Pi Safe Backup Supply (UPS)

Thu Jul 30, 2020 10:01 pm

OK, I'll rephrase that.

Don't mess with charging batteries unless you know what you are doing.

Maybe I'm just hyper sensitive after finding even Microsoft can't get this right.

I ran an MS Surface Pro 4 for a couple of years. It was almost always connected to it's charger. Then the screen started to discolor in one corner. Then it bulged outwards. Then it split away from the frame and I could see the battery expanding inside.

On calling MS they immediately sound worried and asked me to ship it to them for replacement. They even sent me a flame proof package to ship it back to them in.

I got a new Surface Pro 4 in return. Amazing considering it was well outside it's guarantee period.
Memory in C++ is a leaky abstraction .

emma1997
Posts: 868
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pi Safe Backup Supply (UPS)

Fri Jul 31, 2020 2:23 pm

Heater wrote:
Thu Jul 30, 2020 4:32 pm
Do not do that.
I'm no battery expert but from what I read here and elsewhere this is a very bad idea
I am a battery expert and agree it's not a good idea to goof around with DIY charging circuits unless you have the expertise. Specially for BIG batteries and lithium types which can be very cantankerous compared to other chemistries. It's one of the reasons it was omitted in my original post.

However that resistor/diode circuit has been used for small Lipo in literally millions of Walmart style RC toys for decades. Probably at that time outnumbered all other chargers in the world combined 10:1. Maybe not anymore in this age of cell phones but there were relatively few 'accidents' even at it's peak.

I will say the most dramatic and extreme catastrophes I've personally witnessed involved lead acid and NiMh including one fatality. For Lion/Lipo (intentional testing) mostly hissing and smoke.

pidd
Posts: 721
Joined: Fri May 29, 2020 8:29 pm
Location: Birkenhead, Wirral, UK
Contact: Website

Re: Poor Man's Pi Safe Backup Supply (UPS)

Fri Jul 31, 2020 3:33 pm

emma1997 wrote:
Fri Jul 31, 2020 2:23 pm
However that resistor/diode circuit has been used for small Lipo in literally millions of Walmart style RC toys for decades. Probably at that time outnumbered all other chargers in the world combined 10:1. Maybe not anymore in this age of cell phones but there were relatively few 'accidents' even at it's peak.
That is really worrying, if the charger doesn't switch off when the lithium battery is charged, that encourages the fissure growth which ultimately can lead to a fire bomb.

When you consider the big names that have had problems with lithium batteries despite using proper charging circuits with protection etc, using any sort of simple float charger can only be thought of as negligent.

I had a close call, I'm fairly careful when charging lithiums, they are normally charged in my presence but when I'm not there they are only charged in a non-combustible environment but even then I was caught out.

I found one of my lithium camera batteries had obviously had a partial meltdown/fizzout in my camera bag, it wasn't connected to anything when it chose to self destruct. Luckily it hadn't developed to flame level otherwise it probably would have taken the house out as the camera is stored by a pile of bedding etc.

This isn't why I am so pedantic about the safety of lithium, I was already concerned about this flawed technology long before that. I have stacks of NiMH batteries I use for a lot of things and a few lead batteries as well, I have never bought a lithium battery for general use despite having projects that desperately need them.

emma1997
Posts: 868
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pi Safe Backup Supply (UPS)

Mon Aug 03, 2020 4:02 pm

diogen151 wrote:
Thu Jul 30, 2020 1:39 pm
the 18650 battery has a declared capacity of 5.3 Ah, which is volumetrically impossible for the 18650 type.
This is not a problem here, but if someone would perform a UPS with the desired longer power supply with 18650 at best it goes up to 3.4 Ah (e.g. panasonoic NCR 18650B).
dustnbone wrote:
Thu Jul 30, 2020 4:56 pm
the cells pictured in the photo are not 5.4Ah, as the highest density 18650 cells are around 3.5Ah. They're fake and I personally wouldn't trust them.
True that few bargain cells measure even close to what the label says.

Actually those GTL were discussed endlessly on battery forums like Candlepower and ain't half bad. What I mean is, with about half the capacity of top end Samsung 30Q or 50E or Panasonic NCRBD, and one tenth the cost, quite a bargain. I snagged a couple dozen on Ali few years ago for less than a dollar ea. After testing went back to get more but found the price more than double. Who knows what they are selling under that label now if even still around at all.

Lets talk about 'fake'.

On a lark I bought 20pcs of the '10000mah' ones shown below. Again not too bad considering tested about 1.5 ah at 50 cents each. So ordered a cool hundred at 40 cents and waited with baited breath. Having purchased similar quantities of other cells before, the package seemed light. Hmmm... When I pulled one out and hefted it was obviously not from the previous sample lot. Another common chinese bait-n-switch.

Sure enough the scale showed almost 1/3rd weight. I've seen this before and usually don't even need to pull out the B6. I did bother this time and they barely managed 150mah. So out with the dremel and, as expected, a tiny toy lipo inside.

[Dundee voice]
Neow THOT'S ah fike !!!
[/Dundee voice]

lol

I messaged the seller and got instant 100% refund w/o return label which says a lot. Personally I would have settled on 50% off because cells like this do work for some apps. For example they have plenty juice for the few seconds Poor Man's UPS needs for safe Pi shutdown.
Attachments
10000mah_lol.JPG
10000mah_lol.JPG (107.6 KiB) Viewed 527 times
10000_18g.JPG
10000_18g.JPG (71.93 KiB) Viewed 527 times

emma1997
Posts: 868
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: Poor Man's Pi Safe Backup Supply (UPS)

Wed Aug 12, 2020 1:11 pm

hippy wrote:
Thu Jul 30, 2020 9:06 am
With respect to the circuit posted; what's to stop the batteries being run down to below their safe to recharge levels ?
dustnbone wrote:
Thu Jul 30, 2020 4:56 pm
Protection for the 18650s is pretty easy and cheap to implement.

https://www.ebay.ca/itm/2S-8A-7-4V-8-4V ... 2863547887

Those work great for preserving cell life. And yes, don't cost much either. On the other hand cheap CELLS like in prev post, while useful for some applications like this one, IMO not worth protecting. They cost not much more than non-rechargeable.

I suppose a lot depends on how often they are called on to do that 10s shutdown.

At over ten bucks ea the ones in pics below definitely don't fall into that category. Using individual BMSs instead of multi-cell has worked best for me. As seen in the Ebay ad about 25 cents ea so they are lowest cost solution too. You can buy cells with these built-in but they are outrageously expensive. Not worth it if you are handy with a soldering iron (and have a bit of copper guitar tape lying around, lol).
Attachments
IMG_3961.JPG
IMG_3961.JPG (80.66 KiB) Viewed 351 times
IMG_3954.JPG
IMG_3954.JPG (109.69 KiB) Viewed 351 times
ebay_bms.JPG
ebay_bms.JPG (152.82 KiB) Viewed 351 times

nospamprl
Posts: 22
Joined: Fri Mar 04, 2016 3:33 am

Re: Poor Man's Pi Safe Backup Supply (UPS)

Tue Aug 18, 2020 11:00 pm

emma1997 wrote:
Tue Jul 28, 2020 7:10 pm
This DIY circuit senses when main power is removed and then goes into safe shutdown. It eliminated the risk of corrupting SD and other drives if just cutting power. It has few components so easy to build and parts just cost a dollar or two.

The battery only has to keep Pi running for a few seconds so just about any 18650, AA, or even AAA cells can be used. At least couple lithium type or half dozen NIMH or Alkaline to feed the converter. You could also use a 12v security system or car battery for longer term runs.

Two diodes select the higher of the two DC sources for uninterrupted service. A simple resistor divider signals the Pi via GPIO3 to do a safe shutdown when main DC goes away. It reboots the OS automatically when power comes back on.

No special software or programming are needed. Just add the following line to /boot/config.txt:

Code: Select all

dtoverlay=gpio-shutdown,gpio_pin=3,active_low=1,gpio_pull=up
I did this a while back for myself and couple friends. There are lots of requests for safe backups on this forum too (four in the last 24hrs alone) so thought it might help others to put it up here. Attached are schematic and a photo ready to be hooked up to a Pi. As can be seen it simply goes inline between Pi and main supply. This has been tested with Pi4 and Pi2 running Buster but may work with other models and OS too.
emma1997:

My understanding of electronics ends with Ohm's law, but wouldn't it be easier to feed GPIO 5 directly from GPIO 1 (3.3V) ?

I understand GPIO 1 will go down as soon as the power goes off triggering the shutdown process while power starts to be drawn from the battery pack, right?

In this design you could avoid the 2 resistors (which I asume are there to feed 3v to GPIO 5 and should be changed if a smaller power supply is used instead of a 12v).

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

Re: Poor Man's Pi Safe Backup Supply (UPS)

Tue Aug 18, 2020 11:09 pm

nospamprl wrote:
Tue Aug 18, 2020 11:00 pm
My understanding of electronics ends with Ohm's law, but wouldn't it be easier to feed GPIO 5 directly from GPIO 1 (3.3V) ?

I understand GPIO 1 will go down as soon as the power goes off triggering the shutdown process while power starts to be drawn from the battery pack, right?

In this design you could avoid the 2 resistors (which I asume are there to feed 3v to GPIO 5 and should be changed if a smaller power supply is used instead of a 12v).
No. 3V3 is derived on-board from the 5V input. It won't go low until the battery is exhausted. Once the 3V3 goes low, the Pi has ceased to function. It is far too late to think about shutting it down. emma1997's circuit derives a signal from the primary power input side, which goes low when the battery takes over, not when the battery is exhausted.
Signature retired

Return to “General discussion”