henryhanselscott
Posts: 107
Joined: Sun Jan 18, 2015 1:31 pm

Using under voltage warning for pi shutdown

Mon Feb 06, 2017 11:00 am

Would it be possible to use the under voltage warning to trigger a system shutdown? More specifically, could a python script monitor for low voltage and then use os.system("sudo shutdown -h now") to shutdown with minimal risk of corruption?

Thanks,
Henry

pcmanbob
Posts: 7954
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Using under voltage warning for pi shutdown

Mon Feb 06, 2017 11:11 am

Hi.

yes I don't see why not, if you have a read of this post page 4 mikerr posted some code to read the relevant GPIO.
viewtopic.php?f=29&t=82373&start=75

you could modify it to do what you want
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Using under voltage warning for pi shutdown

Mon Feb 06, 2017 11:24 am

While you could "pull" the PWR led status to tell if there is a low power, I remember there is a new feature in "vcgencmd" to tell if there is ever a low power on the system. I read it in some thread about overheat on Pi 3, can't tell which thread exactly for now. Google should help.

A cron job per minute to read that vcgencmd output should work, I think.

henryhanselscott
Posts: 107
Joined: Sun Jan 18, 2015 1:31 pm

Re: Using under voltage warning for pi shutdown

Mon Feb 06, 2017 12:33 pm

Thanks for the replies, very useful information. My thought is to have the pi run on a normal 5 volt supply with a battery backup in the case of a power failure. Then when the batteries begin to get low after a power failure the system would shutdown.

User avatar
davidcoton
Posts: 4537
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Using under voltage warning for pi shutdown

Mon Feb 06, 2017 9:27 pm

henryhanselscott wrote:Thanks for the replies, very useful information. My thought is to have the pi run on a normal 5 volt supply with a battery backup in the case of a power failure. Then when the batteries begin to get low after a power failure the system would shutdown.
But the 5V from your battery is converted from the actual battery voltage. Assuming a switching regulator, the 5V will not dip until the battery is exhausted, which may not leave enough to shut down. You need to monitor the actual battery voltage.

I'm building a heating controller with battery backup. Since the heating won't work with no mains, my strategy is to shut down as soon as the mains fails (well, as soon as it has failed for more than a few seconds). Auto reboot when power is restored.
Signature retired

W. H. Heydt
Posts: 11475
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Using under voltage warning for pi shutdown

Tue Feb 07, 2017 3:40 am

davidcoton wrote:
henryhanselscott wrote:Thanks for the replies, very useful information. My thought is to have the pi run on a normal 5 volt supply with a battery backup in the case of a power failure. Then when the batteries begin to get low after a power failure the system would shutdown.
But the 5V from your battery is converted from the actual battery voltage. Assuming a switching regulator, the 5V will not dip until the battery is exhausted, which may not leave enough to shut down. You need to monitor the actual battery voltage.

I'm building a heating controller with battery backup. Since the heating won't work with no mains, my strategy is to shut down as soon as the mains fails (well, as soon as it has failed for more than a few seconds). Auto reboot when power is restored.
Many modern UPS' have a USB interface that will signal the host system when the batteries are getting low so that an orderly shutdown can be done. It should be possible to find a circuit to do that for homebrew battery backup.

The bigger issue is to make sure that the switch from mains to battery is fast enough not to drop power to the Pi in the transition. My personal experience is that a commercial UPS and a typical "wall wart" PSU suitable for a Pi can accomplish that. How well DIY equipment works is another issue. Probably depends on the amount of capacitance in the DC circuit.

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: Using under voltage warning for pi shutdown

Tue Feb 07, 2017 11:17 am

For DIY-projects: Decoupling via diodes works very fast, no big capacitor is needed!
Greetings, FM_81
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

Return to “General discussion”