The ZeroLiPo is a Lithium-ion Polymer battery power manager for the Raspberry Pi from Pimoroni.
It does not handle battery charging, it simply converts the LiPo 3.7Volts to 5Volts, and provides a low voltage alarm.
Although I've had one of these for ages, I've only just considered using it, possibly for my Bat Call Logger.
The ZeroLiPo is a tiny board which Pimoroni say can be used either by being plugged into the Pi GPIO header, or by being soldered to header pins, allowing an expansion board to be able to be connected to the Pi GPIO pins.
But in the case of the Wolfson sound board used in my Bat Call Logger, neither of these options is going to work, as there is a conflict with the pins required by both boards.
However, the first step is to work out how I'm going to use the ZeroLiPo, and how I can control power on/off. If I'm going to try using my Bat Call Logger in the field, it will need to be headless and powered from a Lithium battery. So ideally I just want a push button to power the system.
Initially I thought it was going to be easy. I expected to be able to use a gpio output to hold the power on via the ZeroLiPo Enable input, and simply set the output low when it was time to turn the power off. However, once the Raspberry Pi had completed the shutdown process, the state of the gpio pins are mostly returned to their initial values.
Note: all gpio pin numbers referenced below relate to wiringPi numbering.With wiringPi installed on the Pi 2 I was using for experimentation, I issued the terminal command:-
...which revealed the default states of the gpio;
I initially tried using gpio22 connected to the ZeroLiPo Enable, as this is high as soon as the Pi is powered up. However, as soon as the shutdown command completed, the pin returned high and the Pi was held in a powered up state.
But there is one gpio pin that goes high when the Pi is powered up, and stays low (when set low) after shutdown: gpio15/TxD. So this is the one to use for the enable input (EN) of the ZeroLiPo.
Here are the main points;
- use a single switch for both power on & power off
- graceful shutdown using command: shutdown now -h
- power off after shutdown
- shutdown & power off if battery voltage drops below alarm level
This needs 1 Pi gpio output and 2 inputs.
power up/down circuit
Here is the development/test circuit;
From cold, pressing the button connects the battery supply (3.7V nominal) to the EN input via a silicon diode. This turns on the 3.3V & 5V supplies to the Raspberry Pi, and gpio15 goes high, holding the EN input high via a 2k2 resistor and a silicon diode. The 2k2 resistor is just there to limit gpio output current while the capacitor is charging. In practice, the capacitor is pretty much charged anyway by the time gpio15 is high.
The input voltage to gpio23 is limited to a safe value by the 10k resistor. Once my Gambas program is running, further button presses are detected via gpio23, which initiates the Linux command: shutdown now -h
My Pi 2 takes approximately 10 seconds to shutdown. Power is maintained on EN by the CR network (47uF & 470k) for about 18 seconds, and then it powers off.
While the system is running, if the battery voltage drops below 3.4V, the program powers down in a similar manner.
Note that the 2k2 resistor connected to Pi pin8 would actually be connected via pin8 on the ZeroLiPo board, since the 8 pin connector on the board blocks pin 8 on the Pi header. This is OK as pin 8 is not connected to any part of the ZeroLiPo internal circuit.
|only pins 1, 2, 6 & 7 are connected to the ZeroLiPo|
the test software
Nothing remarkable here, just a simple gui using Gambas and wiringPi. The basic idea could be incorporated into whatever the target application is, whether gui or command line, and whether written in Gambas, Python or whatever.
' Gambas class file
Public Extern wiringPiSetup() As Integer 'Initialises wiringPi & assumes the calling program uses virtual Pin numbers
Public Extern pinMode(pin As Integer, pud As Integer) 'sets Pin mode to either INPUT, OUTPUT, (or if applicable; PWM_OUTPUT or GPIO_CLOCK)
Public Extern digitalRead(pin As Integer) As Integer 'returns the input state (low=0, high=1)
Public Extern digitalWrite(pin As Integer, value As Integer)
Public Const PIN_OUTPUT As Integer = 1
Public Const PIN_INPUT As Integer = 0
Public Const LO_BATT_PIN As Integer = 7 'Lo battery (< 3.4V)
Public Const EN_PIN As Integer = 15 'Enable battery power
Public Const OFF_PIN As Integer = 23 'start or shutdown required (switch closed)
Using a 1s timer to check switch and alarm status:-
Public Sub Timer1_Timer()
If digitalRead(LO_BATT_PIN) = 0 Then 'battery < 3.4V
Exec ["sudo", "shutdown", "now"]
If digitalRead(OFF_PIN) = 1 Then
Exec ["sudo", "shutdown", "now"]
Note that command "shutdown now" is actually the same as "shutdown now -h" as this is the default action.
the Wolfson sound card problem
The Wolfson sound card is used on my Bat Call Logger, and its a bit of a hack anyway to get it wired and working on a Pi 2 or a Pi 3. As this card sits on the 40pin header of the Pi, it is difficult to see how the Zero LiPo can also be connected to the system to allow battery power to be used.
I thought about cutting the track to pin 7 (which is the only conflicting pin) on the Zero LiPo, so I could use the board as a 'shim' between Pi and Wolfson. It would then be necessary to solder a wire from the Zero LiPo alarm to a suitable free pin on the Pi. This may work, but I still have a mechanical problem with the Wolfson 'pogo pins' which would contact with the Zero LiPo.
The other idea was to use the Zero LiPo mounted free from the Pi/Wolfson combination. This would mean running wires for +5V, +3.3V and 0V between boards, in addition to the low voltage alarm, the EN and BAT+ leads. Very messy!
So for this application I probably need to look for an alternative battery management solution.