5

I am trying to build a battery powered Pi Zero, using a LiPo battery and the Adafruit Powerboost 500. I would like to be able to use the low battery output (LBO) on the powerboost to tell the Pi to shutdown, how feasible is this?

The LBO outputs between 1.8v and 5v whilst the battery is usable, and 0v when it is dead. Could it be connected (possibly via some intermediary) to the GPIO pins?

  • Ha! I'm using that same Adafruit board with my Zero! I'm also having a bunch of trouble with converting the signal from the LBO pin to 3v3. I asked a question here: electronics.stackexchange.com/questions/218427/… -CL. told me to add a pull-up resistor, it seems to work fine for me! – Patrick Cook Feb 21 '16 at 23:24
  • The LBO is pulled high to vBAT unless vBAT drops below 3.2v, which means LBO can only be anywhere between 4.7v and 3.2v then it drops to 0v. This is from the schematics and the learning guide from Adafruit. – Patrick Cook Feb 22 '16 at 0:06
  • I would be tempted to flag this as something to move to EESE - but as it touches something close to my heart I won't 8-) (I have an RPi UPSs, a UPiS "Basic" but I want to run that UPS and the rest of my Home Automation system from a home made 12V SLA battery backed bigger UPS - so I can power the front-door electric lock even if the Mains power fails!) Reading the comment from Patrick Cook on the answer from PandaLions I think you just need a Common Emitter NPN transistor stage to buffer that signal and a pull-up - let me write it up in an answer... – SlySven Feb 22 '16 at 0:39
2

It is not obvious but the LBO output pin on that PWB is connected to the corresponding pin on the IC and to the base of a PNP Common-Emitter stage - however that transistor does have a built-in pair of resistors (a "series" one between the base input pin and the actual transistor base and a "potential-divider" one between the actual transistor base and emitter" together these do provide some sort of pull-up on that output.

If that "series" resistor is quite large it is not possible to be certain that it would be strong enough to also pull the LBO pin up strongly enough to drive a RPi GPIO pin to the high state unless that was configured to have it's own input configured with a "Pull-up" (which actually is the case for the first few GPIO pins by default I believe, unless over-ridden in the config.txt file or by some other means).

The nature of an "open-drain" output is that it is almost like a single-pole single way switch between the output pin and ground- when the output is in a "high" logic state the switch is open and the voltage on the pin floats to what ever the external components set but when the output is in a "low" logic state the switch is closed and the pin is pulled to ground hard and will draw current in from what ever (positive voltage sourced) circuitry is connected. The only complication is that it is probably not good to let the external supply to whatever "pull-up" is used to exceed the supply to the IC with the "open-drain" output unless the resistor in series with that is high enough to prevent damaging currents to flow into that output via the (parasitic/protection) diodes that usually exist between all I/O pins on an IC and the positive supply rail (anode to pin, cathode to positive supply rail) which help to protect against static damage to a naked IC and are often inherent in the physical semiconductor design!

Those same type of parasitic/protection diodes are on the Raspberry Pi's GPIO pins and that means that when the RPi is un-powered a GPIO pin will look like a diode on the GPIO pin with the anode on the GPIO pin and the cathode to the (now at ground voltage as the device is un-powered) RPi 3.3V rail. Anything that is connected to the RPi - like an open drain output from the Powerboost board would also be grounded via that diode- fair enough that this is not an issue when the RPi is switched off because the Powerboost has a low-battery but a direct connection of the LBO output with an pull-up to the RPi's 3.3V rail will also illuminate the LBO-LED on the Powerboost board until the RPi is powered-up!

tl;dr;

I would suggest the following circuit:

A simple Common Emitter stage with a 10KOhm pull up resistor (R1) onto the LBO pin and a series 47KOhm resistor (R2) to the base of a generic NPN transistor (Q1) stage with a collector resistor of 2.2KOhm (R3) to the RPi +3.3Volt supply and another 47K series resistor (R4) to an RPi GPIO (input) pin.

R1 provides enough pull-up current to turn on Q1 under "normal" conditions, R2 prevents the forward biased Base-Emitter junction from clamping the LBO pin to only 0.7V above ground when the transistor is turned on - otherwise the LBO LED on the Power Boost board would be constantly on, even when the battery was above 3.2 volts! R3 permits enough current to flow through Q1 to allow the transistor to saturate so that a typical VCEsat of 0.5 Volts can be achieve which will be the input level via R4 that the RPi will see (no internal Pull-up or Pull-down should be set on that GPIO pin). When the Power boost battery level drops below the 3.2V level the drive to Q1's base is still enough to operate but when the LB Output is pulled to ground level by the IC on the Power boost module there will be no more drive current, Q1 will switch off and its collector voltage will raise to the 3.3V RPi level, by the action of R3 so when the RPi detects a High level on the selected pin then it is time to have a GPIO monitoring script run in the background from rc.local (or whatever new-fangled method systemd forces its users to use) to execute shutdown -h -p now Battery exhausted on PowerBoost unit!

Hope this is of some use.

P.S. See my question at how-does-init-get-to-know-about-power-events this does have a Python script that monitors a GPIO pin for a change to initiate a shutdown which you ought to be able to modify to use with this answer.

1

The best answer would be for you to get a DAC (digital-to-analog) converter and use that to measure the voltage of said LBO. I recommend the MCP3008 chip. Then, you could have a script that measures the voltage there and shutdown when it goes to the minimum you specified.

If you want a quick fix, you could just make a voltage divider and arrange it such that 5V on the LBO is 3.3V on the GPIO. The low threshold of a GPIO pin is about 1.1V or lower. So if the LBO+divider is at 1.1V or lower, the Pi will see it as a low. It's up to your script how to handle that.

  • You can't make a voltage divider, as the pin is open-drain, so the voltage divider will only output 0v, no matter what. – Patrick Cook Feb 21 '16 at 23:24
  • Using an ADC is overkill, and unnecessarily complex. For a start you need a running program to monitor. A far simpler, and more reliable method if to use a comparator. I have build many such circuits using an LM311 although there are probably better chips which will run off 3.3V. – Milliways Feb 22 '16 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.