smartyPies.com

BananaPi with UPS

I'm running a BananaPi (Model 1) on bananian[1], headless, as a git server. Originally I had a SSD attached, but I switched back to a MicroSD card with 64GB, which suffices for this purpose.
Unfortunately the filesystem crashed on uncontrolled powerdowns, so I wanted to attach the Banana to a UPS.

StromPi 1 extension board

I got the StromPi 1 extension board from joy-it [2], which is said to be "compatible" with BananaPi (BPi). The manual [3] describes two modes this boards can run, namely UPS and WIDE, the latter allows to run a Pi within a range from 6V- 36V. For detection of main power failure the Test-Pin must be connected to some GPIO port. The corresponding software [4] provides two Python programs for the UPS mode. One sends an email when the system switches to aux power, the other shuts down the system safely.

Preparation required

I wanted to stack the board on top of the BPi, to keep it compact. There are two obstacles:

  1. AV Video OUT is in the way
  2. more severe, Pins 2+4 of BPi shall not be used for power in, see [5]. This is different from Raspberry Pi!

The solution for me was a wire cutter, see below. Of course, the board doesn't have to sit on top, keep it where you want, just observe the correct wiring.

Wiring (see image)

Banana Pi with Strom PI - wiring

Software

Installing the required python-dev package for the software didn't work. Since GPIO can also be accessed through the shell [7] and [8], I was going for a shell script.
To map GPIO numbers and names between BananaPi and RaspberryPi Model A, see [9] and [10], the first pin layout drawing. You can run the LED experiment on the raspberry page from shell to verify the assignment of GPIO 0 of BananaPI to BCM 17 of RaspberryPi. I checked other ports and found that GPIO 1 of BPi was addressed by BCMs 18 +19 RPi, while the other ports were as expected.

Here is the powerdown.sh:

 #! /bin/bash
 # (c) 2017, Guido Lutterbach, smartypies.com

 # init GPIO  17 = GPIO0 on Bananapi
 GPIOPORT=17

 # reset GPIO   -   not necessary for boot script, helpful for command line tests
 if [ -d /sys/class/gpio/gpio$GPIOPORT ]
 then
   echo $GPIOPORT > /sys/class/gpio/unexport
   sleep 0.5
 fi
 # setup GPIO
 echo $GPIOPORT > /sys/class/gpio/export
 echo in > /sys/class/gpio/gpio$GPIOPORT/direction
 # this prevents noise signaling "power down"
 echo up > /sys/class/gpio/gpio$GPIOPORT/pull

 while $true
 do
     CURRENT_STATE=$(cat /sys/class/gpio/gpio$GPIOPORT/value)
     if [ "$CURRENT_STATE" == "1" ]
     then
         #echo "main power down; check again in 30 sec."
         sleep 30
         CURRENT_STATE=$(cat /sys/class/gpio/gpio$GPIOPORT/value)
         if [ "$CURRENT_STATE" == "1" ]
         then
             break
         fi
     fi
     # check every 1/10 sec
     sleep 0.1
 done
 shutdown -h now

Running this script from command line and unplugging the main supply, the UPS switched to battery mode (green LED off, blue LED on). Plugging main power in within 30 sec, reverted this and the Banana kept running. Otherwise, shutdown after 30 seconds. WOMM!
I start this script as a system demon during boot. There are many pages describing the usage of init scripts e.g. [11], please follow their instructions.

Finally

For starting the BananaPi after a power failure, with StromPI board and main power up, push the reset button.

Links

  1. bananian-download page
  2. Joy-It, StromPi 1 product page, German
  3. StromPi 1 manual, German
  4. StromPi 1 software, German
  5. "* Those 5V pins(CON3 Pin2 & CON3 Pin4) are voltage output pins from BananaPi's PMIC(AXP209). They can NOT be power input pins from external power source. Otherwise, it may damage the BPi board.", taken from BananaPi product page
  6. lemaker forum -"Power via GPIO CON3 ?"
  7. Accessing RaspberryPi GPIO via shell
  8. wiringpi-Shell GPIO utility
  9. BananaPi product page- CON3 (GPIO Headers)
  10. RaspberryPi Models A+B - GPIO
  11. debian-administration.org -Making_scripts_run_at_boot_time..