Hacking a powerbank to use as a Pi UPS

      Comments Off on Hacking a powerbank to use as a Pi UPS

The small embedded Pi computers use a SD card as the storage medium. SD however has a fatal flaw, if its being written to while the power is interrupted, the card gets corrupted. Best case it damages some file you don’t care about, worst case it will actually damage the card itsself over time, I’ve killed at least two cards in my phone this way. For Pi’s that are used a few hours a day, a random power failure isn’t usually a problem you’ll encounter often, but for one that’s connected and on 24/7 like the server running this website is, it’ll need good power to make sure it doesn’t get damaged.

And because its powered by USB, why not get a USB ‘powerbank’ to do it.

Turns out most powerbanks don’t support charging the battery and using it with something hooked up at the same time. Neither did the one I bought for this purpose. So its time to take it apart and modify it!

Opening the powerbank, its held together with four small screws. The decorative paper is sandwiched between the black inner housing and the clear outer housing, and will of course also be modified.

After prying open the case, I found out both the charging circuit and boost circuit use the same chip. That explains why it will not charge and boost at the same time. The chip is a TP4303F, which turns up a Chinese datasheet and a simple component diagram, its actually quite obvious how it works, charging using a buck converter and discharging using a boost converter using the same exact inductor. Furthermore, it has the common “battery protection” circuit built in.

I combined the two schematics to form this, this is the powerbanks’ circuit diagram:

And my thought went to the little TP4056 boards I previously used to charge loose 18650 li-ion cells, so I cut a trace on the powerbank to use its USB power input connector, soldered on three wires, and soldered on one of the TP4056 breakout boards. The circuit diagram now looks something like this:

Its working, Red on the RP4056 signifies its charging (from the white USB lead), Blue on the TP4303 signifies its generating 5V output.

So far, this little Hack makes it possible to charge and discharge the cell at the same time. It does have some drawbacks, this way the 5V gets converted to battery voltage and back to 5V again, adding to the energy losses. The Orange Pi board that I’ll be connecting barely draws a single watt idle, so the total losses, on the grand scale of things, aren’t that bad. Lets just hope the components don’t die from constant use and cause the power failure they were intended to prevent.

The next step is to cut down the TP4056 board size to allow it to fit inside the enclosure. I thought about redoing the whole PCB, but just doing a piggyback board gives the same result for less effort.

Cm grid for reference. The making-of has its own post over here.

All hooked up and it fits back in the original package. Its now downstairs powering the Orange Pi server which is hosting this website.

Some future improvements:
The way the boost converter is set up doesn’t allow me to simply bypass the whole thing with a diode and directly forward wall power as long as its available. If I ever build my own circuit for a powerbank, I’ll make sure to add that.
Another thing I’d like to add in the future is some sort of feedback wire to the ‘Pi to notify it’s lost the wall power and needs to shut down safely in the event it doesn’t come back up after a pre-set time. Thats all for a version two.