Having my Raspberry Pi Media server get corrupted by a power off event, I decided to have a go at fixing it.

Originally my idea was to make a UPS powered totally from the TV USB connection but then I decided that it may be pushing the current rating. Also the USB port may be needed so the final PiUPS will only use the USB voltage to tell it the TV is on.

My prototype gets its USB signal from a couple of wires connected to a USB hub. Main power is supplied from a 12V plug pack, and backup power uses a 9.6V NiCad, trickle charged from the plug pack. The brain is a PIC12F629.

PiUPS-Proto

The green connector on the left has the USB power sense, Power Good to the Pi, and Pi Running signal back to the PiUPS.

On the right, the vacant green connecter above the battery connector is for the 12V plug pack.

Above that is the USB connector supplying 5V power to the Raspberry Pi.

When the power is ok and the TV USB is turned on, the PIC turns the 5V power on to the USB out connecter, powering up the Pi.
Then after a delay, the Power Good signal to the Pi is asserted.

The Pi then tells the PIC-UPS that it is running.

When the TV USB is turned off (or the plug pack/battery supply is getting low), the Power Good signal asks the Pi to shut down. The Pi will tell the PIC-UPS it has shut down, then after a delay, the power to the Pi is turned off. On the proto, a relay is used to switch power to a 3 terminal switch mode regulator, but the final will just enable a switching regulator chip directly.

Once I have the code running on the Pi to test it all, I may produce a circuit board and kit for those interested in building one.

There will be some code adjusting, like hysteresis on the supply voltage sensing, and maybe serial handshaking in place of the digital logic  lines or at least a build option.