UPS Project
Uninterruptible Power Supply for Raspberry Pi
This is a blog to share my UPS project. You'll see pictures, code, schematics, and test information. I have never written a blog before so good luck to me!
Introduction
This uninterruptible power supply was designed to provide operating power to a Raspberry Pi (RPi) computer. It uses a diode switch to select wall power if available, but switch to battery backup automatically should there be a power failure. Battery voltage is supplied by 8xAA Nickel-Metal Hydride batteries. To ensure that power will be available, I selected Tenergy brand Centura Low Self Discharge cells, such as these available from Amazon. They are intended to maintain charge over long periods of storage.
The Tenergy AA size battery has built in low self discharge technology that prevents it from losing its power after long storage periods. Once charged, it can be stored for 12-24 months with a high capacity percentage left. Unlike typical NiMH batteries, Centura Low Self Discharge high capacity AA battery can retain up to 85% of capacity even if stored for 1 year!
A buck converter is used to adjust the input voltages from these two sources down to the operating level of the RPi. I use this one from Amazon for most purposes. Since it has a USB 'A' connector, I can use a standard power cable to connect power to the RPi.
Start with an alternative
The UPS project described here is comprehensive in its functionality. So if you find that off-putting, start here with an alternative.
A minimal UPS can be constructed from the parts just described: a battery pack, two diodes and a buck converter, alone. Here is one website's version of such a circuit: Home DIY Electronics. I highly recommend this as a first UPS circuit for your Raspberry Pi adventures.
However, unless you can be there to watch over your RPi and UPS board, this circuit has a few shortcomings and questions:
- You have to remove the battery pack to recharge it at some point.
- If your ac power "goes away" as if from a tripped GFCI, the batteries could be damaged by over-discharge.
- If your RPi crashes, you have no way to either automatically or remotely restart it.
- How long has your RPi spent on UPS power?
- How is the quality of the power at your remote location?
- You can manually measure the battery voltage to get an idea of whether the batteries need charging, but you have to be there.
- As the battery nears discharge, there is no way to automatically shutdown the RPi before power disappears..
A better solution
I often have RPi computers operating in remote locations where I cannot be there to watch them.
The UPS boards are installed in 5 running systems, and currently support 3 RPi 3B computers and 2 RPi Zero W computers. Earlier prototype versions support a RPi Zero W (UPS2) and an earlier version (UPS1) supports the Home Assistant computer here. I also have several RPi computers running with commercial UPS devices such as those sold by APC. All of those were installed prior to the development of the UPS I devised here.
The current board design for the third UPS model (UPS3) is revision 2.
Description
An ESP8266 variant, the ESP8285 microcontroller, is used to control the operation of the UPS. The specific controller used is the Wemos D1 Mini Lite available from Amazon. It does not control the input power switching as that is automatic due to diodes being wire OR'd. But it has sensors so that it knows if wall power is available, a measurement of the battery voltage, and whether the client RPi is running properly (watchdog & deadman).
The UPS control code is available on github.
The Wemos device indirectly controls the power switching in the UPS. If the ESP microcontroller is reloaded via Over The Air (OTA) updating, restarted, or even just crashes, its output pins will go high impedance and no longer maintain control of the power. This is avoided by setting up an ATTiny microcontroller as a serial to parallel converter. A serial interface connection with a special protocol was designed to allow the ESP device to control output pins on the controller. That ATTiny code is available on github.
The ATTiny outputs switch an ULN2003 NPN transistor bank implemented in an integrated circuit. These in turn control PNP power transistors (main and load) used as high-side switches.
The major functions of the UPS controller are to reboot the client RPi, restart the ESP controller, and stop the client RPi and power it and the ESP controller completely off.
To reboot the client RPi, the UPS controller will generate a signal to the client that tells the RPi to shutdown. After a minute to allow everything to complete, then the RPi will be powered off and after a few seconds, it will be turned back on, hopefully to restart correctly.
Restarting the ESP controller resets all of the variables and counters. It does not affect the power going to the client RPi.
To help keep the RPi running, the UPS includes a dead man system to monitor a toggled output signal from the client RPi. Should that output signal stop toggling, the UPS controller will assume that the RPi has stopped running and go through the reboot sequence.
Should wall power be turned off for an extended period of time, such as a GFCI breaker tripping, the NiMH batteries could be damaged from over-discharge. If the UPS controller detects a low battery voltage, it go through a shutdown sequence, turning the client and itself off.
Ordinarily, the UPS must be restarted manually by pressing the start push button seen in Picture 1. But with the introduction of the lightning detection system to this network, the same UPS shutdown function is used to turn the system off to avoid damage from surges during a lightning storm. The Autostart controller built into the Disconnector 1 board will electrically press the start button to power everything back up, and restart the client RPi.
Schematic
Pictures
The photos are of a version 1 printed circuit board, implemented to support RPi 3B computers. The version 2 board moves some pins around for convenience.
Web Interface
The controller supports a web server to show status and allow control. The main display typical presents a screen such as:
There is a help screen which is available as:
This is UPS-control-OTA6
Running UPSx-control v1.5d
Add these to base URL:
/ledtest blinks status LEDs (but not power LEDS)
/freeheap displays heap space
/con turns charger on
/coff turns charger off
/pause pauses watchdog for 1 hour
/reboot to reboot the client computer
/restart to restart the ESP controller
/stop to halt the client, and then power off the client and the UPS (ESP8266)
/help to display this page
This screen lets you start the LED test, turn the battery charger on or off, and control the major states of the UPS. The blue highlighted words are links to the appropriate function on the controller.
Options
Even though the UPS uses low self discharge batteries, I decided to implemented a constant current battery charger to the system. That project is documented here as the Doubler/Charger project. The charger is controlled via web page interface. The local Home Automation system also can turn the charger on and off. Charge current is limited to under 30 mA so that it can run for many hours and not cause damage to the battery string.
When lightning detection was implemented on the local network (see my blog Lighting Detection and Surge Mitigation), I implemented a system to shutdown the client RPi computers and the UPS as well. A circuit (picture; Disconnector 1) that disconnects the UPS from wall power for protection from surges was wired up. As mentioned earlier, normally the UPS must be manually started with a push button, The Disconnector 1 board includes an ATTiny to restart the UPS after a preprogrammed period of time after the shutdown of the system. See the autostart project for more details.
The current board design for the third UPS model (UPS3) is revision 2.
Description
An ESP8266 variant, the ESP8285 microcontroller, is used to control the operation of the UPS. The specific controller used is the Wemos D1 Mini Lite available from Amazon. It does not control the input power switching as that is automatic due to diodes being wire OR'd. But it has sensors so that it knows if wall power is available, a measurement of the battery voltage, and whether the client RPi is running properly (watchdog & deadman).
The UPS control code is available on github.
The Wemos device indirectly controls the power switching in the UPS. If the ESP microcontroller is reloaded via Over The Air (OTA) updating, restarted, or even just crashes, its output pins will go high impedance and no longer maintain control of the power. This is avoided by setting up an ATTiny microcontroller as a serial to parallel converter. A serial interface connection with a special protocol was designed to allow the ESP device to control output pins on the controller. That ATTiny code is available on github.
The ATTiny outputs switch an ULN2003 NPN transistor bank implemented in an integrated circuit. These in turn control PNP power transistors (main and load) used as high-side switches.
UPS Block Diagram |
The major functions of the UPS controller are to reboot the client RPi, restart the ESP controller, and stop the client RPi and power it and the ESP controller completely off.
To reboot the client RPi, the UPS controller will generate a signal to the client that tells the RPi to shutdown. After a minute to allow everything to complete, then the RPi will be powered off and after a few seconds, it will be turned back on, hopefully to restart correctly.
Restarting the ESP controller resets all of the variables and counters. It does not affect the power going to the client RPi.
To help keep the RPi running, the UPS includes a dead man system to monitor a toggled output signal from the client RPi. Should that output signal stop toggling, the UPS controller will assume that the RPi has stopped running and go through the reboot sequence.
Should wall power be turned off for an extended period of time, such as a GFCI breaker tripping, the NiMH batteries could be damaged from over-discharge. If the UPS controller detects a low battery voltage, it go through a shutdown sequence, turning the client and itself off.
Ordinarily, the UPS must be restarted manually by pressing the start push button seen in Picture 1. But with the introduction of the lightning detection system to this network, the same UPS shutdown function is used to turn the system off to avoid damage from surges during a lightning storm. The Autostart controller built into the Disconnector 1 board will electrically press the start button to power everything back up, and restart the client RPi.
Schematic
Pictures
The photos are of a version 1 printed circuit board, implemented to support RPi 3B computers. The version 2 board moves some pins around for convenience.
Picture 1: UPS3v1 Circuit board |
Picture 2 (below) shows a UPS3v1 board implemented to support a RPi Zero W. Because power requirements are less, I used a smaller buck converter, instead of the one mentioned in the Introduction. Everything on the UPS3v2 control board is the same.
Picture 2: A UPS3v1 implemented to support a RPi Zero with camera. |
Web Interface
The controller supports a web server to show status and allow control. The main display typical presents a screen such as:
This is UPS-control-OTA6 at 192.168.2.61 supporting host zero4 Running UPSx-control v1.5d on a ESP8266_WeMos_D1_mini_Lite Reboots: 0 Running for 523981 seconds DM time to go: 117 Battery voltage(avg): 10.62 @ 97.7 degrees F Supply power is on On battery: 0 seconds Charger is off for 509139 secondsYou can see which host it supports, how long it has been running, whether wall power is on or off, and how long it has been off in the past.
There is a help screen which is available as:
This is UPS-control-OTA6
Running UPSx-control v1.5d
Add these to base URL:
/ledtest blinks status LEDs (but not power LEDS)
/freeheap displays heap space
/con turns charger on
/coff turns charger off
/pause pauses watchdog for 1 hour
/reboot to reboot the client computer
/restart to restart the ESP controller
/stop to halt the client, and then power off the client and the UPS (ESP8266)
/help to display this page
This screen lets you start the LED test, turn the battery charger on or off, and control the major states of the UPS. The blue highlighted words are links to the appropriate function on the controller.
Options
Even though the UPS uses low self discharge batteries, I decided to implemented a constant current battery charger to the system. That project is documented here as the Doubler/Charger project. The charger is controlled via web page interface. The local Home Automation system also can turn the charger on and off. Charge current is limited to under 30 mA so that it can run for many hours and not cause damage to the battery string.
When lightning detection was implemented on the local network (see my blog Lighting Detection and Surge Mitigation), I implemented a system to shutdown the client RPi computers and the UPS as well. A circuit (picture; Disconnector 1) that disconnects the UPS from wall power for protection from surges was wired up. As mentioned earlier, normally the UPS must be manually started with a push button, The Disconnector 1 board includes an ATTiny to restart the UPS after a preprogrammed period of time after the shutdown of the system. See the autostart project for more details.
Comments
Post a Comment