Testing a Pi UPS module

Lead Image © Kanlayavadee Thephasdin na Ayuthaya, 123RF.com

Emergency Power

When the Raspberry Pi is connected to a car ignition or the USB port on a TV, you run the risk of data loss with a hard shutdown. The Pi UPS bridges short lapses in the power supply and shuts down your Rasp Pi safely when the power remains off.

The Raspberry Pi with its meager consumption of only 3 watts is predestined to be the brain for an infoscreen [1] or a simple entertainment center for a TV in the home, car, or RV. Generally, the Raspberry Pi only needs 5 volts from the USB port of a monitor or TV. It can also snatch up power from the on-board power supply of a car or truck via a USB adapter.

However, this method of receiving power has a huge disadvantage. When you shut the TV off or turn the ignition off, you cause an abrupt interruption in the flow of power to the Raspberry Pi. In the long run, you will have to reckon with the danger that these interruptions can lead to a loss of data or a damaged operating system. To prevent the occurrence of such problems, you must perform an orderly shutdown of the Raspberry Pi before turning off any devices the Pi is working with. This approach is not so easy when the Raspberry Pi is hidden behind something like the dashboard of a car.

Emergency Power for the Raspberry Pi

For those who want to be certain that the Raspberry Pi has time for a proper shutdown, the Pi UPS [2] for the GPIO port of the Raspberry Pi is an excellent solution (see Table  1). German manufacturer CW2. electronics offers an uninterruptible power supply (UPS) that you can attach to the little computer to protect it in the event of loss of power from the regularly used source. The power is drawn from a battery pack, and the computer is shut down after a time interval of your choosing.

Table 1

Pi UPS

Manufacturer

CW2. electronics GmbH & Co. KG

Voltage supply

Micro-USB

Emergency power source

6 AA batteries (7.5-12V, min. 1,000mAh)

Operating status indicator

3 LEDs

Signaling

I2C bus (pin 3 and pin 5)

Software

Pi-UPS-Monitor-App (download as DEB)

Delivery contents

Pi UPS, bracket for 6 AA batteries

Price

EUR 29.99

The Pi UPS is a 55x40mm (~2x1.5-inch) board that sits on the GPIO socket of the Raspberry Pi, as shown in Figure 1. The UPS routes the pins of the GPIO port upward so it is possible to plug in additional Raspberry Pi extension boards. You can hook up the battery cable via terminal connections to the UPS. Be sure to push the black negative pole of the cable into the left connection jack that is labeled GND. Installation guidelines [3] with detailed illustrations in English can help during setup.

Figure 1: The LED lights up in green to signal that electricity is flowing to the Raspberry Pi from the USB power supply that has been hooked up.

Be aware that when a UPS board is added to the Raspberry Pi, it will no longer fit into all Raspberry Pi housings because of the increase in size. If you find that a particular housing is not large enough, you will need to work on it to create openings and notches as needed. Make sure you create an opening for the micro-USB connection, because the power supply for the Raspberry Pi comes via the added board.

The colored LEDs on the board signal the current status of the Pi UPS. When the green LED (LED1) lights up, this means that the contact between the 5 volts from the USB power supply and the board is correct. If the orange LED (LED2) lights up, this means something is not right with the battery. If you see orange, you should check the connection to the board or change out the batteries. The red LED (LED3) lights up as soon as the battery has to start supplying power to the Raspberry Pi (Figure 2).

Figure 2: If a sudden loss of power occurs, the Raspberry Pi can pull the necessary electricity without interruption from the battery.

The UPS Daemon in Raspbian

The Pi UPS delivers power to the Raspberry Pi as long as the batteries last and without the need for additional software. To protect the batteries and avoid an uncontrolled shut down if the batteries run out, you should install the Pi UPS monitor [4] as a background service. The program watches over the condition of the UPS and, during a preset period of time, sends a shutdown signal to the operating system in the event of a loss of power (Figure 3).

Figure 3: The Pi UPS monitor app works in the background and makes it possible for the Raspberry Pi to shut down safely in the event of a loss of power.

CW2. electronics manufactures the Pi UPS and offers the Pi UPS monitor in the form of a DEB package for Raspbian and other Raspberry Pi distributions based on Debian. Installation requires only that you download the package onto the Raspberry Pi and then manually install it via the package manager with dpkg:

$ wget http://www.piusv.de/support/piusvmonitor.deb
$ sudo dpkg -i piusvmonitor.deb

The software does not need additional dependencies in Raspbian. The Pi UPS monitor consists of an active background service. No additional front end or command-line tool provides output on the condition of the batteries or the status of the UPS. By using pgrep to check the process ID of the program piusvmonitor, you can at least figure out whether the service has started successfully:

$ pgrep -l piusv
2185 piusvmonitor

The service should be active immediately after installation of the package and a system restart. The only commands available for the Pi UPS monitor are those that start and stop the service:

$ sudo piusvd start
$ sudo piusvd stop
$ sudo piusvd restart

The monitor tool provides a little bit of feedback via a logfile under /usr/share/piusvmonitor/log.piusv. In the log, PRI_POW stands for "primary power" and means the Raspberry Pi is drawing power from its power supply. SEC_POW signals the loss of electricity and the startup of the alternative power supply, or "secondary power." If the UPS monitor shows BAT_LOW, then the batteries are either low or not connected correctly to the UPS.

You can enter more scripts to be executed in the configuration file of the Pi UPS monitor, /usr/share/piusvmonitor/config.piusv:

Autostart=1
Logfile=/usr/share/piusvmonitor/log.piusv
TurnOffTime=10
Sleep=1
PRI_POW=
SEC_POW=
BAT_LOW=
ShutDownScript=

You do not need to name the ShutDownScript. The monitor service executes a shutdown -h now by itself with a loss of power. You can change the startup characteristics of the UPS monitor and the logfile storage location. Note that Autostart=0 deactivates the automatic start of the service. Additionally, you should adjust the length of time in seconds that the UPS has to begin shutdown of the Raspberry Pi with a loss of power. You should also adapt the check interval.

The manufacturer only offers the Pi UPS monitor for Raspbian. Although you can install the DEB file under Raspbmc, you will need to set up the build-essential package on the system for the build process via the following command:

$ sudo apt-get install build-essential

CW2. electronics does not offer official support for OpenELEC or Arch Linux. However, there's talk in the support forum of the desire to put together a support package.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content