pjc123
Posts: 921
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

How to detect shutdown

Thu Oct 11, 2012 2:33 am

I have a headless pi and I need a way to perform a clean shutdown in the event that I lose wifi access to the pi, something in the OS or one of my programs locks up the pi, or maybe I just don't have remote access at all and need to shut it down. So I am going to wire a momentary switch to one of the GPIO ports to enable a clean shutdown using a loop that looks at the status of the switch and then issues a shutdown command when it goes to low. I am also wiring a toggle switch to the 5v line so I can turn the pi power off after the clean shutdown and then on again to boot it up again. Note that I could just do a reboot with only a momentary switch, but I also want the capability to just turn the pi completely off. Anyway, this is all easily doable.

My problem is that the pi will be enclosed in a sealed box and will not be visible, so I have no way of telling if the pi is shutdown, and that it is safe to reset it with the toggle switch (I can't look at the on-board LED's). I was hoping to wire a led from either the 3.3v or the 5v GPIO pins to the front panel of the chassis, but the pi does not really shutdown like a x86 Linux computer does, meaning that all the power rails are still active after a shutdown.

So, any ideas on how I can detect that it has shutdown in such a situation?
My Raspberry Pi Project Page:

https://www.flaminghellmet.com/launch/

User avatar
Dweeber
Posts: 606
Joined: Fri Aug 17, 2012 3:35 am
Location: Mesa, AZ
Contact: Website

Re: How to detect shutdown

Thu Oct 11, 2012 4:52 am

You can detect when the RPi is "off" by watching the UART TX pin which stops sending 3.3v the RPI is in shutdown mode.

Article on how someone made a circuit to detect it and make use of it...

http://www.raspberrypi.org/phpBB3/viewt ... TX#p185458
Another Article:
http://www.boeeerb.co.uk/pitx-an-atx-st ... or-the-pi/
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com

pjc123
Posts: 921
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: How to detect shutdown

Thu Oct 11, 2012 11:45 am

Ah, that might do the trick, although I am concerned about the exact point in the shutdown procedure that the led is off; in other words, have the file systems been unmounted before it turns off, because that is my main concern. If that is true then this would work, as all I would need to do is run an LED from the front panel to the UART TX pin and I am good to go.
My Raspberry Pi Project Page:

https://www.flaminghellmet.com/launch/

User avatar
Dweeber
Posts: 606
Joined: Fri Aug 17, 2012 3:35 am
Location: Mesa, AZ
Contact: Website

Re: How to detect shutdown

Thu Oct 11, 2012 11:53 am

When the 3.3v is missing from UART TX, the RPi is shutdown completely so there is nothing left to sync to the disk it is already down.
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com

pjc123
Posts: 921
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: How to detect shutdown

Thu Oct 11, 2012 2:35 pm

Dweeber wrote:When the 3.3v is missing from UART TX, the RPi is shutdown completely so there is nothing left to sync to the disk it is already down.
Just tried it out and the filesystems are indeed umounted before the LED goes out. Fantastic.
My Raspberry Pi Project Page:

https://www.flaminghellmet.com/launch/

ski522
Posts: 394
Joined: Sun Sep 30, 2012 2:22 pm

Re: How to detect shutdown

Thu Oct 11, 2012 2:53 pm

pjc123 wrote:I have a headless pi and I need a way to perform a clean shutdown in the event that I lose wifi access to the pi, something in the OS or one of my programs locks up the pi, or maybe I just don't have remote access at all and need to shut it down.
You should figure out what's locking up the PI...that's extremely unusual for Linux. In the 10+ years of using Linux, the only time I've ever had it lock up was due to a physical hardware problem (IE bad disk, bad memory, overheat, etc). Even poorly written apps crashing shouldn't be locking up Linux.

pjc123
Posts: 921
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: How to detect shutdown

Thu Oct 11, 2012 3:52 pm

ski522 wrote:
pjc123 wrote:I have a headless pi and I need a way to perform a clean shutdown in the event that I lose wifi access to the pi, something in the OS or one of my programs locks up the pi, or maybe I just don't have remote access at all and need to shut it down.
You should figure out what's locking up the PI...that's extremely unusual for Linux. In the 10+ years of using Linux, the only time I've ever had it lock up was due to a physical hardware problem (IE bad disk, bad memory, overheat, etc). Even poorly written apps crashing shouldn't be locking up Linux.
I was just listing several various scenarios; my pi is not locking up. I just wanted a way to perform a clean shutdown given my particular setup.
My Raspberry Pi Project Page:

https://www.flaminghellmet.com/launch/

User avatar
Boeeerb
Posts: 43
Joined: Thu Sep 27, 2012 2:40 am
Contact: Website

Re: How to detect shutdown

Fri Oct 12, 2012 2:13 pm

I've used my PiTX on the same SD install and to date it's still running perfectly. The TX pin goes low at the same point as the OK/Act light flashes to indicate it's successfully halted. If your really worried you can add a 3 second timer (will involve more complex circuitry) then cut the power, but as I mentioned I haven't had any corruption problems
Find me on Twitter - @Boeeerb
Website - http://www.boeeerb.co.uk

User avatar
jackokring
Posts: 816
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: How to detect shutdown

Fri Oct 12, 2012 2:43 pm

Also the TX may find utility as a TX, and so some little adaptation may be needed for it to work off stop bits only. Otherwise some naughty download may switch off your pi. I'm not sure if UART can be switched off easily. Surely it would be better if the pin 13 difference on each board were hard wired to this function, instead of a more general IO.

Having said that it would be nice if the I2C came up initialized, but would it really provide an education in version revision and software adaptation?
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

Return to “Interfacing (DSI, CSI, I2C, etc.)”