Battery Powered Project

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I am working on a battery powered car and want the Pi to shut down  
automatically if the battery starts to go flat to try to prevent SD card  
corruption. I am a beginner to bash scripts! I will run this via crontab...

#!/bin/bash
powerstatus=$(vcgencmd get_throttled)
if [ $powerstatus="throttled=0x1" ]
then
echo Under Voltage Detected - Shutting Down
sudo halt
else
echo Voltage Normal
fi

Obviously it is not working!! Could someone correct and explain for me  
please.

Battery Powered Project
Hello Simple!

Tuesday January 12 2021 12:14, you wrote to All:

 > I am working on a battery powered car and want the Pi to shut down
 > automatically if the battery starts to go flat to try to prevent SD
 > card corruption. I am a beginner to bash scripts! I will run this via
 > crontab...

 > #!/bin/bash
 > powerstatus=$(vcgencmd get_throttled)
 > if [ $powerstatus="throttled=0x1" ]
 > then
 > echo Under Voltage Detected - Shutting Down
 > sudo halt
 > else
 > echo Voltage Normal
 > fi

 > Obviously it is not working!! Could someone correct and explain for me
 > please.

You have another 2/3 possible issues :-

1.  crontab will only run the script at the defined point of time so you need
to run it often OR better still as a subtask from a routine that WILL run if
the battery is low at a given point (not almost flat) to shutdown the system ,
NOTE the term shutdown by using similar to shutdown -h now and not halt which
may well not close down any processes running first and possbly cause
curruptions on your system disk / SD etc.

2. As a follow on from 1 , you need a low level process that is constantly
running say with a sleep of nn seconds that tests the battery state and if  
good
sleeps or runs process similar to your bash script but not it and suggest say
a little C process as it would use less resources.

3. As a follow on from both of the above.
You should check what battery setting you have for throttled and have it set  
to
at least 25% battery power if you have a lot of proceses that can be running  
at
any one time and if needed a higher value.

I have a similar set of processes but linked to a APC UPS so see package
apcupsd.

Vincent


Re: Battery Powered Project
Quoted text here. Click to load it

You need spaces in the test:-

    if [ $powerstatus = "throttled=0x1" ]

Without the spaces you are just testing if '$powerstatus="throttled=0x1"'
is not an empty string, and it never will be an empty string.


--  
Chris Green


Re: Battery Powered Project
Chris Green wrote:
Quoted text here. Click to load it
Brilliant - many thanks - works a treat - I was almost there!!

Re: Battery Powered Project
On 12-01-2021 13:50, Simple Simon wrote:
Quoted text here. Click to load it

It won't matter here, I guess, and you needed it for debugging, but  
normally never output to the console from a background script. So  
perhaps remove the echos now that it works.

Slightly more importantly, it's good practice to put variables in quotes  
when testing them (the part between brackets) because you never know  
what may be inside. If there's a space, or the variable is empty, your  
script will break.

Re: Battery Powered Project
Quoted text here. Click to load it

I'm curious... does this actually work for low battery detection?

Unless you're wiring the Pi directly across a battery that's giving out
somewhere around 5V (for example a 6v lead acid), most of the time you'll
have a voltage regulator between you and the battery.  That regulator will
aim to keep providing 5V as the battery is going flat.  When the voltage
sags below 5V it means the battery is so empty it can't maintain that, which
means it's in a very steep part of the voltage decline.

I'd expect it to be so steep you don't get enough time to do any meaningful
shutdown, but I could be wrong.  What battery setup do you have and how does
it work out in practice?

Theo

Re: Battery Powered Project
On a sunny day (12 Jan 2021 21:43:03 +0000 (GMT)) it happened Theo

Quoted text here. Click to load it

That is a valid argument for say detecting a low mains voltage.
It does not however cover a fault in the regulator itself.

I like the idea as extra test for fault conditions
like too much voltage drop over USB cable by high loads etc..
You can make it log the error, or switch off high load / routines first
before shutdown, sound an alarm, etc.
A very common error in wallwart supplies is bad filter caps on the output,
causing a high ripple on the 5V, this could perhaps detect that.
Did no know about the low voltage check option.

Re: Battery Powered Project
On 12 Jan 2021 21:43:03 +0000 (GMT), in

Quoted text here. Click to load it

Yes, except...

At the low current draw of the Pi, unless the battery is rather small
a cutoff of 5 V for a 6 V battery is 1.67 Volts per cell (Vpc) and
that's way too low if you want to prevent premature failure due to
overdischarge.

You might get away with this long term if the battery capacity is low
to begin with because then 1.67 Vpc might be say 80 - 90% discharged.
But for a larger battery, say an automotive starting battery, a
voltage of 1.67 Vpc at the current rate drawn by a Pi is way
overdischarged and the battery will experience short life.

The upside to all of this is that there probably won't be many
outages. If regular outages are expected, then a much higher cutoff
voltage needs to be set to prolong battery life... the bigger the
battery the higher the cutoff.

--  
Jim H

Re: Battery Powered Project
On 12 Jan 2021 21:43:03 +0000 (GMT)

Quoted text here. Click to load it

Lithium cells have a linear-ish discharge curve, from 4.2V down to
around 3V. Any sensibly designed lithium battery will cut off its
output at the chosen lower bound, because if it completely discharges,
it's dead forever. Not a 'steep' decline, a 'fall off the wall' decline.

It's a good idea to have some independent means of anticipating this
point.

--  
Joe


Re: Battery Powered Project
Quoted text here. Click to load it

But lithium ion cells don't work for this application.  We need 5V.
One cell is too little, two cells is too much.
One cell would start at 4.2V which is too low to reliably run a Pi.
Two cells would start at 8.4V which is dangerously high for the Pi, and the
proposed 5V cutoff would only come in below 2.5V per cell which is bad for
the cells.

As mentioned 6V lead acid doesn't work for a starting battery - it might be
OK for a 'leisure' battery that is fine with deep discharge, but again we're
on a part of the curve where the battery is absolutely flat and declining
fast.

Possibly LiFePO4 might be better, but a pair of cells at 3.6V fully charged
is still too dangerous for the Pi.

4x alkaline cells might just about manage it - 1.6V per cell when new, ie
6.4V total, which is a bit dangerous but maybe OK.  A gradual decline - I
don't know where the Pi low voltage detection is but flat would be about
1.1V per cell or 4.4V total which is probably detectable.  So if you don't
mind throwing away cells at 20% capacity it might just work.

Theo

Re: Battery Powered Project
On Wed, 13 Jan 2021 23:37:18 +0000, Theo wrote:

Quoted text here. Click to load it
In the soaring world we use 12v SLA (sealed lead-acid) batteries to power  
our radios, flight recorders FLARM and and various navigation systems.  
Most instrument panels draw 400-800 mA when fully powered up, so a 7AH  
battery is good for flights of over 7 hours.

I use Yuasa NP7-12 batteries. This is a 12v 7.2Ah sealed battery, so can  
be installed any way up and is also sold for use in small business UPSs.

In my glider I use a 12v->5v 3A DC converter (under 6 quid from eBay,  
where they are sold for blinging up cars with festoons of LEDs) for  
powering instruments which want a 5v supply. Mains chargers which shut  
off or switch to float mode at full charge are available for these  
batteries.

If you go this way, and want to implement low-voltage shutdown for the  
Pi, connect your low-voltage detector inputs across the battery and set  
the shut-down point to 10.5v.

If the low-voltage detector is a Pi hat, make a voltage divider from a  
68K and a 27K resistor, put that across the battery and connect leads  
from each side of the 27K resistor to the low-voltage detector: when the  
battery is drawn down to 10.5 volts, there will be 3 volts at the low  
voltage detector. Or use a 10K linear potentiometer and set it to output  
approximately 3 volts.  
  

--  
--  
Martin    | martin at
We've slightly trimmed the long signature. Click to see the full one.
Re: Battery Powered Project
On 13/01/2021 23:37, Theo wrote:
Quoted text here. Click to load it
switch mode regulator will work with any of them.

Given that you want around a one amp capability

https://hobbyking.com/en_us/turnigy-1800mah-2s-12c-lipo-receiver-pack.html

is a suitable pack

and

https://hobbyking.com/en_us/turnigy-hv-sbec-5a-switch-regulator-8-42v-input.html

is a suitable regulator.

HOWEVER that is still only half the story, as, presumably, you want to  
run it off mains as well - or do you?

My point here is that a charger that will both charge the pack correctly  
AND have a spare amp to drive the Pi is not so easy.

If you are happy to go and change batteries every so often, well then  
presumably you will want a much bigger battery.

Anyway hobbyking is the go-to place for chargers regulators and  
batteries - ship world wide, and product is good quality.


--  
Future generations will wonder in bemused amazement that the early  
twenty-first century?s developed world went into hysterical panic over a  
We've slightly trimmed the long signature. Click to see the full one.
Re: Battery Powered Project
On 13 Jan 2021 23:37:18 +0000 (GMT)

Quoted text here. Click to load it

    One cell and a DC-DC converter to give you a regulated supply,
monitor the cell so you can shut down (well) before there's too little to
run the converter.

--  
Steve O'Hara-Smith                          |   Directable Mirror Arrays
C:\>WIN                                     | A better way to focus the sun
We've slightly trimmed the long signature. Click to see the full one.
Re: Battery Powered Project
On 14/01/2021 10:18, Ahem A Rivet's Shot wrote:
Quoted text here. Click to load it
It's slightly simpler and more efficient to use a step down from two cells.

--  
The theory of Communism may be summed up in one sentence: Abolish all  
private property.

We've slightly trimmed the long signature. Click to see the full one.
Re: Battery Powered Project
On Thu, 14 Jan 2021 11:04:55 +0000

Quoted text here. Click to load it

    It's only simpler if you look at what's on the converter board :)

--  
Steve O'Hara-Smith                          |   Directable Mirror Arrays
C:\>WIN                                     | A better way to focus the sun
We've slightly trimmed the long signature. Click to see the full one.
Re: Battery Powered Project
On 14/01/2021 11:46, Ahem A Rivet's Shot wrote:
Quoted text here. Click to load it
No, that's not true. To step up you need to use a buck converter with a  
choke big enough to store energy to push the voltage up. To step down  
you only need a choke to smooth HF ripple, and transistor efficiency  
goes up with voltage and down with current, so that's a win win too.

--  
"Corbyn talks about equality, justice, opportunity, health care, peace,  
community, compassion, investment, security, housing...."
We've slightly trimmed the long signature. Click to see the full one.
Re: Battery Powered Project
On Thu, 14 Jan 2021 12:21:52 +0000

Quoted text here. Click to load it

    Sure that's all on the board :) From a system perspective it's just
a board with battery in and 5V out :)

Quoted text here. Click to load it

    Oh I agree a step down only is a simpler board, but either way it's
an off the shelf small component.

--  
Steve O'Hara-Smith                          |   Directable Mirror Arrays
C:\>WIN                                     | A better way to focus the sun
We've slightly trimmed the long signature. Click to see the full one.
Re: Battery Powered Project

Quoted text here. Click to load it

Not true.  The step-down inductor needs to store energy too.

David

Re: Battery Powered Project
On 14/01/2021 14:17, David Higton wrote:
Quoted text here. Click to load it

It isn't a step down inductor.

you just use variable PWM  on the raw voltage. All you need to do is use  
a cap  and some form of current limiter - a resistors works but  
dissipates power



Quoted text here. Click to load it


--  
Those who want slavery should have the grace to name it by its proper  
name. They must face the full meaning of that which they are advocating  
We've slightly trimmed the long signature. Click to see the full one.
Re: Battery Powered Project

Quoted text here. Click to load it

Just a short form of words - I was referring to an inductor in a step
down regulator.

Quoted text here. Click to load it

There are regulators that use capacitors, sure (commonly step up, e.g.
for EIA-232 line drivers), but they inherently require significant
resistance in the switch elements to limit the current, so they're
lossy.  For a low power application the losses don't matter, but in
the case discussed here, I don't think you'd want that level of loss.
It works out the same as a linear regulator, according to my maths.

Using an inductor in a conventional step-down switching regulator is
much more efficient, and of course requires the inductor to store
energy.

(Apologies for the delay in replying - the news server I use changed
its implementation of NNTP and I have had to modify my news transport
client's code to suit.)

David

Site Timeline