Battery Powered Project

Hello Simple!
Tuesday January 12 2021 12:14, you wrote to All:
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
Reply to
Vincent Coen
Loading thread data ...
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.
Reply to
Simple Simon
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
Reply to
Chris Green
Brilliant - many thanks - works a treat - I was almost there!!
Reply to
Simple Simon
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.
Reply to
A. Dumas
Not being much help, but...
I'm aware of Under Voltage problems from entries in journalctl. It seems to me that listening for events logged to journalctl would be a pretty common thing to do. So common that there should be some standard way of doing it. Some kind of standard Observer pattern on jounalctl. Does anyone know of one?
Reply to
Pancho
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
Reply to
Theo
On a sunny day (12 Jan 2021 21:43:03 +0000 (GMT)) it happened Theo wrote in :
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.
Reply to
Jan Panteltje
Well that's just another problem with systemd. When coming up with something similar in Apache, I could tell apache to log to a process that tripped certain (security relevant) events.
There ought to be a way to tell systemd to do similar so you can have a watchdog attached...but who knows how to do it?
--
?Puritanism: The haunting fear that someone, somewhere, may be happy.? 

H.L. Mencken, A Mencken Chrestomathy
Reply to
The Natural Philosopher
One way to get a rapid notification of entries written to a log is the use 'tail' in a script.
Running "sudo tail -f /var/log/messages" from a console shows you each message as it is written to /var/log/messages, so a script started a boot time to run with sufficient privilege to read those log entries could easily use tail to read messages as they are written and filter out the ones of interest with grep or awk and use them to , for instance force a clean shutdown on low battery, something like
#!/bin/bash tail -f /var/log/messages | awk
Reply to
Martin Gregorie
On 12 Jan 2021 21:43:03 +0000 (GMT), in , Theo wrote:
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
Reply to
Jim H
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
Reply to
Joe
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
Reply to
Theo
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 
 Click to see the full signature
Reply to
Martin Gregorie
They do.
No, it wont. That isn't in the *battery* - that's in whatever is drawing current off it. I have many lthium packs with no such ptotection
No, again it goes on down to zero, 3V is just approximately the point at which irreversible damage starts to happen.
The way to run a lithium in this application is to use a 2 cell lithium, a constant voltage constant current charger limited to 8.4V and probably no more than the battery mAh capacity divided by one hour... and a switched mode 5V regulator to feed the Pi and then somehow monitor raw battery voltage and switch it all off when it gets to say 6.6V and hope that the SMPS and monitoring circuit don't then still draw enough to damage the battery, or even if it is take it on the chin and replace the battery when that happens.
I would imagine that the whole setup would cost more than the Pi itself
--
?It is dangerous to be right in matters on which the established  
authorities are wrong.? 
 Click to see the full signature
Reply to
The Natural Philosopher
switch mode regulator will work with any of them.
Given that you want around a one amp capability
formatting link

is a suitable pack
and
formatting link

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  
 Click to see the full signature
Reply to
The Natural Philosopher
To get round that use a latching relay 'start' circuit, and when the battery voltage gets too low unlatch the relay- Zero power demand then.
--
W J G
Reply to
Folderol
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 
 Click to see the full signature
Reply to
Ahem A Rivet's Shot
Its getting as complicated as a renewable energy grid though isn't it?
--
In todays liberal progressive conflict-free education system, everyone  
gets full Marx.
Reply to
The Natural Philosopher
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. 
 Click to see the full signature
Reply to
The Natural Philosopher

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.