Nazo
Posts: 18
Joined: Sun Jul 29, 2012 12:01 pm

Viability of using a USB power bank as a UPS?

Thu Jun 15, 2017 4:08 am

First, sorry if I got the wrong forum. I'm a beginner at any sort of programming/etc and can't really do much of this sort of thing myself, so I'm a beginner in that respect.

Anyway, to the heart of the matter. I'm curious about how viable it might be to sort of rig up a USB power bank to act as a UPS system. Preferably a cheap one. I have a Raspberry Pi 2 being used as a server on my LAN mostly for some basic stuff like acting as a Squid proxy and network file sharing (music, videos, etc etc) on my LAN. What's more, I have multiple USB power banks, at least one of which has a decent output, boasts 4000mAh power (probably actually accurate as I think it uses two 18650s and usually those cheap Chinese generics are closer to 2000mAh than anything else,) and is capable of providing power while being plugged in to charge. Obviously a USB power bank can definitely power a Raspberry Pi just on its own, but there are two things to consider in using one as any sort of UPS type of solution:

First, how well can a DC-DC converter of the sorts these use hold up? But at the same time, as far as using a third party DC-DC converter goes, I'm not sure if this is optimal for several reasons. (They usually put the battery protection circuitry on the board rather than the battery itself in most of these cases, so I have to add on one. The charging portion would also have to be added on externally and I'm not sure how well that meshes with the output -- something a lot of power banks already implement ways to handle no doubt.) These things use fairly small DC-DC converters with no real cooling or anything, so I'm not sure how well it could handle if it's constantly running. On the other hand, most of these are built for up to 2.1 amps output for phone charging (which can still take a while, so they're obviously meant to run for more than just a few minutes at a time) and even though I do have an external harddrive plugged in (one designed for one USB 2.0 bus so has to be able to run from 500mA power even when it does run) it actually stays off most of the time (though I have it on there so I can use it for network sharing of media and such, so it can come on and run for a while at a time at least in theory though I haven't really used it all that much for all that I went to the trouble to set it up. I specifically setup Raspbian to spin it down when it goes long enough without being used however.) I have to assume the possibility that it will be properly utilized from time to time though.) I'm not sure how much the RPi2 uses on average (using ethernet rather than WiFi btw) for itself, but even with the extra 500mA I imagine it's quite considerably less than the 2.1A these cheap power banks are supposed to be able to put out.

Second, while most of the time it wouldn't even matter since usually it's just dealing with simple power blinks, what it really needs to work well is some means of actually tracking the battery status. It could potentially lose power for long periods of time at least once in a while. I really ideally would prefer in these scenarios, even if I'm not able to manually shut it down that it would be able to shut itself down automatically. But of course it would need some way of monitoring the battery. For example, if you could wire something directly to the battery where it detects the voltage and then some way for software to actually monitor this and issue a proper shutdown if it goes too low. A simple enough thing for a programmer with the appropriate hardware design knowledge no doubt, but I have no clue how I could possibly even do such a thing as I am neither. So my questions here are: 1. is it possible using some simple software (maybe the built in scheduler?) to somehow check the battery from time to time and shut down automatically if it goes below a certain threshold (probably something like 3.5V as much lower and the DC-DC converter likely craps out plus you want a bit of leeway -- it can probably go as low as 3.4 but likely starts crapping out around that sort of range, randomly shutting off and on) and 2. is it possible to more or less wire it directly to the RPi or does it require some external circuitry that might be more complex than I can really do to pull off such a thing? (Yeah, I've always been more interested in the RPi for its ability to act as a super efficient, minimal, tiny computer than for its ability to program for utilizing and managing external interfaces even if it is even more amazing at that sort of thing probably.) This also begs the question of if such a thing could be checked early on in the startup process so it maybe could refuse to continue if it's still too low (though I guess some sort of emergency bypass would be necessary if it needed to be booted without the power bank for a while or something.) Unfortunately, in my experience even journalized filesystems can have issues from time to time if improperly shut down at just the wrong moment or too frequently so really I would be a lot more comfortable with the whole idea if the server could just shut itself down.

Is the whole idea just a little too far out there? I currently have it plugged into the same UPS as my desktop PC, but the UPS has to be plugged into the PC (higher priority by far) and sometimes when the power goes off for a while in the middle of the night it wakes me up as even with almost everything off the UPS still drains sufficiently to eventually start making horrible warning noises and forces me to get up while 75% asleep and manually shut it off. I haven't had to do this since setting up the server, but it's probably inevitable and I don't think while 75% asleep I'm going to want to deal with properly shutting the thing down. I really like the idea of something independent just for it and nothing else, plus this is kind of neat as it makes for a more clean and minimal solution that even could be somewhat portable or something if I ever wanted to adapt the idea to some other use yet while just using a power bank in itself is quite portable, if it runs down it still can cause problems, so even for portability acting more like a UPS could be useful. Also, I just plain wanted to move it to another room where I keep stuff like my router and modem rather than in the bedroom for a bunch of reasons but I still don't want it to just shut off unsafely every time there's a power blink.

W. H. Heydt
Posts: 11065
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Viability of using a USB power bank as a UPS?

Thu Jun 15, 2017 5:17 am

Most "power banks", and especially the inexpensive ones, are unlikely to support input and output power simultaneously and that is what a UPS has to do. In addition, many power banks cannot be charged at a rate higher than their discharge rate (I've seen ones that can supply 2A, but can only be charged at 1A, for instance).

Really, if you need a UPS, buy a UPS. For small applications I use 250VA units that go for about $40. I have seen claims that some UPSes will shut off if they don't see enough load, but I haven't had that problem even when the load is just a Pi at idle. Testing is always in order, though.

There are some small UPSes, including at least one (MoPower) that mounts directly to the GPIO pins.

In the final analysis, you need to decide how long a power outage you need to endure and size your power backup system to match. That can be "until power is restored" or "long enough to do a clean shutdown" or some combination of both.

Nazo
Posts: 18
Joined: Sun Jul 29, 2012 12:01 pm

Re: Viability of using a USB power bank as a UPS?

Thu Jun 15, 2017 6:05 am

W. H. Heydt wrote:Most "power banks", and especially the inexpensive ones, are unlikely to support input and output power simultaneously and that is what a UPS has to do. In addition, many power banks cannot be charged at a rate higher than their discharge rate (I've seen ones that can supply 2A, but can only be charged at 1A, for instance).
This one officially states an output of up to 2.1A. Whether it will do this while charging I can't say. I know for a fact it supports output while charging because, well, I plugged something in while it was charging and it worked. Part of my whole question here is how much the RPi uses (very approximately -- I know the RPi2/3 supports proper power saving features so will vary a fair bit, but it must more or less average at some sort of range) and thus how much I should count on needing from it anyway though.
Really, if you need a UPS, buy a UPS. For small applications I use 250VA units that go for about $40.
I'm dead broke but I already have power banks originally intended for different purposes that see no use now including the one I was thinking of for this.
In the final analysis, you need to decide how long a power outage you need to endure and size your power backup system to match. That can be "until power is restored" or "long enough to do a clean shutdown" or some combination of both.
Honestly, I really just want it to handle blinks without shutting off and otherwise I don't care if it only lasts five minutes before shutting down so long as it properly and safely shuts down with no incomplete writes along the way. A LAN server isn't very useful when there is no LAN.

MarkDH102
Posts: 357
Joined: Fri Feb 13, 2015 3:18 pm

Re: Viability of using a USB power bank as a UPS?

Thu Jun 15, 2017 1:53 pm

I have been using a RavPower RP-PB19 16750mAh for just such a purpose.
It originally powered a model B, but is now powering a Pi0
Both have an EDIMAX Wifi dongle and are powering a home brew ATMEGA 328p board.
It has been going for just under a year. We've had loads of short and a few long (> 4 hours) power cuts in that time.
The Pi just keeps on running. No issues.

W. H. Heydt
Posts: 11065
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Viability of using a USB power bank as a UPS?

Thu Jun 15, 2017 3:38 pm

Nazo wrote:
W. H. Heydt wrote:Most "power banks", and especially the inexpensive ones, are unlikely to support input and output power simultaneously and that is what a UPS has to do. In addition, many power banks cannot be charged at a rate higher than their discharge rate (I've seen ones that can supply 2A, but can only be charged at 1A, for instance).
This one officially states an output of up to 2.1A. Whether it will do this while charging I can't say. I know for a fact it supports output while charging because, well, I plugged something in while it was charging and it worked. Part of my whole question here is how much the RPi uses (very approximately -- I know the RPi2/3 supports proper power saving features so will vary a fair bit, but it must more or less average at some sort of range) and thus how much I should count on needing from it anyway though.
By most standards, Pis *don't* support proper power saving features. All Pis except the Pi0/Pi0W have input current limiting polyfuses. One can, therefore specify the maximum current required. What the actual average current requirement is will depend on load and peripherals. A good way to determine that for your specific setup is to measure it. That said, as a rule of thumb, figure your requirements assuming rated maximum, which is to say 2A for a Pi2B or 2.4A for a Pi3B.
Really, if you need a UPS, buy a UPS. For small applications I use 250VA units that go for about $40.
I'm dead broke but I already have power banks originally intended for different purposes that see no use now including the one I was thinking of for this.
You have my sympathy...I've been there. That is still the actual recommendation, though.
In the final analysis, you need to decide how long a power outage you need to endure and size your power backup system to match. That can be "until power is restored" or "long enough to do a clean shutdown" or some combination of both.
Honestly, I really just want it to handle blinks without shutting off and otherwise I don't care if it only lasts five minutes before shutting down so long as it properly and safely shuts down with no incomplete writes along the way. A LAN server isn't very useful when there is no LAN.
Well...*my* solution to that is to put the network devices (router, switches) on a UPS as well. Even a small UPS, such as I mentioned already, would be sufficient to cover a router and switch as well as a Pi. This may explain why there are 2 1350VA, 2 1500VA and a 250VA in the same room I'm sitting in, and three more large, plus one small UPS in another room to be used when I haul a load of equipment off the run registration at a convention (the reason for the extra units is so that I don't have to tear down and reconnect the normal home stuff every year...it's a time vs. money thing).

Nazo
Posts: 18
Joined: Sun Jul 29, 2012 12:01 pm

Re: Viability of using a USB power bank as a UPS?

Fri Jun 16, 2017 1:35 am

W. H. Heydt wrote:By most standards, Pis *don't* support proper power saving features.
I'm not sure. It seems the Pi2 and 3 support CPU governors and the like. If it isn't actually scaling I'm not sure I see the point (and if it is this will affect power usage regardless of intent.)
That said, as a rule of thumb, figure your requirements assuming rated maximum, which is to say 2A for a Pi2B or 2.4A for a Pi3B.
I don't think the Pi2 uses 2A. Actually, I noticed the official FAQs page covers it and I just missed it before: https://www.raspberrypi.org/help/faqs/#powerReqs Quite a bit more conservative than the 2A you've mentioned. In fact, I won't be maxing out the USB by any means (remember, the HD is intended to run on an official USB 2.0 500mA maximum specification and that's spin-up.) They are saying 1.8A on that page basically and that's an extreme case with higher USB output than I'll have going. Also, average tends to be more important so long as the maximum is within the maximum specifications of the power source itself. A high average would be much tougher compared to a low average. As this system isn't really working all that hard I would say the average is likely a lot more conservative than you might assume. Unfortunately, this all makes it tougher to figure out where it would really stand. I guess I'll have to rig up something with a current meter at some point, but that's easier said than done.
That is still the actual recommendation, though.
Fine. Recommendation ignored due to not really being possible at this time. Moving on to the original discussion...

MarkDH102 wrote:I have been using a RavPower RP-PB19 16750mAh for just such a purpose.
It originally powered a model B, but is now powering a Pi0
Both have an EDIMAX Wifi dongle and are powering a home brew ATMEGA 328p board.
It has been going for just under a year. We've had loads of short and a few long (> 4 hours) power cuts in that time.
The Pi just keeps on running. No issues.
Bit overkill for this one, lol. A 16750mAh bank should indeed last quite a long while. A lot more than four hours if I'm not very much mistaken. But really the problem is that one is too far off scale. It's designed to be able to quick-charge multiple phones and that sort of thing with a sustained output significantly higher than anything the RPi is even capable of (in fact, it could handle multiple RPis.) It has a much higher quality DC-DC converter (actually multiple converters even.) So the question of how well a cheaper one like this would handle doesn't really apply there since basically that RPi is not stressing that thing at all.

W. H. Heydt
Posts: 11065
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Viability of using a USB power bank as a UPS?

Fri Jun 16, 2017 3:09 am

Nazo wrote:
MarkDH102 wrote:I have been using a RavPower RP-PB19 16750mAh for just such a purpose.
It originally powered a model B, but is now powering a Pi0
Both have an EDIMAX Wifi dongle and are powering a home brew ATMEGA 328p board.
It has been going for just under a year. We've had loads of short and a few long (> 4 hours) power cuts in that time.
The Pi just keeps on running. No issues.
Bit overkill for this one, lol. A 16750mAh bank should indeed last quite a long while. A lot more than four hours if I'm not very much mistaken. But really the problem is that one is too far off scale. It's designed to be able to quick-charge multiple phones and that sort of thing with a sustained output significantly higher than anything the RPi is even capable of (in fact, it could handle multiple RPis.) It has a much higher quality DC-DC converter (actually multiple converters even.) So the question of how well a cheaper one like this would handle doesn't really apply there since basically that RPi is not stressing that thing at all.
I run a Pi2Bv1.1 and an RPF 7" display from a 10Ah power bank. it'll run for about 5 hours. Depending on peripherals and load, 4 hrs on 16.75Ah battery may or may not run it dry, but it's not a bad number to work with.

Also remember when dealing with commercial LiPo/Li Ion battery packs, the Ah rating is at 3.7v, while the Pi is going to be drawing current at 5v. The best thing to do is to convert everything Watts or Watt-hours so you're dealing in consistent units.

Nazo
Posts: 18
Joined: Sun Jul 29, 2012 12:01 pm

Re: Viability of using a USB power bank as a UPS?

Fri Jun 16, 2017 5:21 am

My rule of thumb is to assume about 85% efficiency for each conversion with DC-DC converters. They'll claim to be as high as ~92% or so, but that's at a specific optimal voltage range which 5V is never in (usually something like 32V or so depending on the converter.) So I consider it to be ~72% efficiency (or 28% loss) in total counting both conversions. I'm not sure about the method the RPi uses for downvolting. (It's really too bad they don't support lithium ion more directly as the usual working voltage range falls pretty well within the range of devices like these. Most DC-DC converters crap out around 3.3V anyway, so it's about the same range, but more efficient.)

But, like I said, I'm fine with my 4000mAh power bank only lasting a few minutes as long as it shuts down properly. That is the part that concerns me in that respect rather than total run time. EXT4 (which, of course, I'm using for the Linux partition -- the FAT32 boot partition shouldn't really be accessed pretty much ever outside of me manually doing updates or changes myself) is very good at handling things like power loss, but I HAVE had Linux systems fail due to too many reboots. (I've often found myself using ATi videocards as they just tend to suit my needs at the times best but I've had a few times where drivers were so unstable the system would actually outright freeze in Linux from time to time, forcing me to hard reset. And that's without using desktop composition stuff which I hate anyway.) I just want some sort of way for it to know that it needs to be shutting down if it's on battery for long before it actually shuts off forcefully. (I do also worry as I've seen DC-DC converters come back on when the voltage is very close to its range -- I think it depends on current usage to some extent when you're at its lower limits. So I worry about it trying to boot back up and failing. However, while I thought this was one of those power banks that are automatically on when you plug something in, it seems you have to push a button to turn it on. Ironically this same button does not turn it off... Only unplugging the device and waiting will cause it to turn off again. I've never seen a power bank setup quite that way, but I guess it solves this particular problem.) I suppose even if it could just somehow know when it's on the battery at all (regardless of actually being able to monitor the battery itself) and then shut down if it is on it for more than, oh, say five minutes, this would still work sufficiently for my needs.

Also, just to be clear, what I was talking about there about actual average current usage and etc is how much strain it is for the converter itself. (The batteries will be fine. It's two 18650s as far as I can tell without pulling it apart -- which I may well do later and recase it anyway -- and I do honestly believe they probably are at least close to that officially rated 2000mAh capacity as this is pretty typical of cheap generics. Worst case scenario, assuming full 2.1A output on the other end, that would be about 1.05A to each battery, so effectively we'll call this 0.5C which is pretty much the most optimal current draw one could ask for and well within safety margins. Ok, adding that ~15% efficiency at that end it would be 1.2A which is still only 0.6C or well within a very safe margin all the same (I like to keep cheap batteries below 0.7C if I can.) But the DC-DC converter is minimal and tiny, designed to fit into a small enclosure, so that is the part that concerns me. It may not really be designed to be able to handle outputting more than just a bit for hours at a time. Assuming it doesn't just pass the input straight through while charging. I have no clue how I could possibly test such a thing. Assuming it is not simply passing the input straight through, my point here is that the DC-DC converter would be constantly running to power the RPi even if it is plugged in.

W. H. Heydt
Posts: 11065
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Viability of using a USB power bank as a UPS?

Fri Jun 16, 2017 4:44 pm

Nazo wrote:My rule of thumb is to assume about 85% efficiency for each conversion with DC-DC converters. They'll claim to be as high as ~92% or so, but that's at a specific optimal voltage range which 5V is never in (usually something like 32V or so depending on the converter.) So I consider it to be ~72% efficiency (or 28% loss) in total counting both conversions. I'm not sure about the method the RPi uses for downvolting. (It's really too bad they don't support lithium ion more directly as the usual working voltage range falls pretty well within the range of devices like these. Most DC-DC converters crap out around 3.3V anyway, so it's about the same range, but more efficient.)
USB specification is for 5v, hence the use of that for input power. Otherwise, the Pi would have to have an added upvolt converter...which would add cost and complexity, both anathema to the RPF design philosophy. There is another very good reason for the Pi not to run directly from Li Ion batteries. That is that such batteries are pretty finicky about charge and discharge characteristics. IF Pis ran directly from such batteries, it would be a boon to the construction industry for the work in replacing houses that had be inadvertently burned down.

I do use Lithium based "power banks" to run Pis, but I don't attempt to charge them in use or use them as a substitute for an actual UPS. I use them in "mobile" applications...such as a pseudo-laptop or an electronic name badge.

What I would suggest is that you look into the MoPower UPS kit. It has the kind of control you're looking for. It won't use Li Ion/LiPo batteries (due to the above referenced charging issues), but it can use most anything else including supercaps for a short term supply while the Pi is shut down cleanly. Having referenced it, mosespi will probably be along shortly to give details.

Nazo
Posts: 18
Joined: Sun Jul 29, 2012 12:01 pm

Re: Viability of using a USB power bank as a UPS?

Sat Jun 17, 2017 5:36 am

W. H. Heydt wrote:What I would suggest is that you look into the MoPower UPS kit.
No.

W. H. Heydt
Posts: 11065
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Viability of using a USB power bank as a UPS?

Sat Jun 17, 2017 3:37 pm

Nazo wrote:
W. H. Heydt wrote:What I would suggest is that you look into the MoPower UPS kit.
No.
Okay... Have it your way... I hope you keep up on the insurance payments on your dwelling.

User avatar
GeekMike
Posts: 6
Joined: Mon Jun 27, 2016 8:42 pm

Re: Viability of using a USB power bank as a UPS?

Thu Jun 29, 2017 9:39 pm

Nazo:
I feel your pain. For a simple solution that can communicate low battery and manage power-outages,
check out: http://www.lifeguardsolution.com/

It can communicate via GPIO to alert your system of power loss. It can also monitor a "Heartbeat" to ensure the SBC is running.

Nazo
Posts: 18
Joined: Sun Jul 29, 2012 12:01 pm

Re: Viability of using a USB power bank as a UPS?

Thu Jun 29, 2017 9:57 pm

That seems like the right sort of idea, but no mention of costs. I'm guessing it's probably still too much. Actually, from the look of it, they're probably largely looking for OEMs and sell in bulk rather than individuals anyway.

PuHuang
Posts: 2
Joined: Tue Jan 23, 2018 3:51 pm

Re: Viability of using a USB power bank as a UPS?

Tue Jan 30, 2018 5:48 pm

Well, just saw this post, think the UPS from Wug Robot probably can help www.wugrobot.com/prod/PiON.html

Nazo
Posts: 18
Joined: Sun Jul 29, 2012 12:01 pm

Re: Viability of using a USB power bank as a UPS?

Wed Jan 31, 2018 1:00 am

Well, the idea here is to find a way to make use of existing "power banks" that have fair capacity on their own. This has a few problems in that respect. For starters, it would be impossible to in any way use it with one of these power banks. It uses a step-down converter (and it seems like not such a great one given the range they seem to expect to go down to get to 5V,) so requires a fairly high voltage. While connecting batteries directly wouldn't be entirely impossible, I would then have to have some charging mechanism that wouldn't interfere and it would probably even have to be on each individual battery or something which drives this all into a level of complication that just seems unnecessary. I don't have a lot of confidence that a NiMH battery pack will really deliver all that much by way of long term reliability (I really do not miss NiMH and think it's past time for normal consumer battery usage to move on and for things to stop using it -- far fewer charge/discharge cycles and I swear they just wear out on their own even when you aren't using them.) It also doesn't really mention anything about how it handles current which is pretty big with RPi use sometimes. I've had troubles with one RPi "power supply" thing that doesn't produce enough current to handle it plus a very small screen together well and can just sort of reboot (momentary power loss I guess) if something I plug in uses too much power.

BTW, I couldn't find any mention of price or even where to buy (are you supposed to e-mail them and give them direct account info or something? Sheesh) but my bet is this thing isn't very cheap.

Anyway, for now I'm just making do as it is with this sort of thing. No proper way of handling low voltage or anything, but then I haven't really ever truly gone with any ideas where I truly need such a thing anyway. It would be nice on the one I'm using as something of a LAN server, but lately I'm using it less anyway. I've only had problems with a RPi becoming unbootable after a power loss once (and ironically it wasn't even that one.) Mostly I was just hoping there might be some sort of really simplistic little board out there that basically was like a UPS control board but which could handle lithium ion type setups or something of the sort. Nothing terribly complicated. I mean, if I were going for complicated and had the money I would even just stick the whole thing on an actual UPS.

Return to “Beginners”