User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Detecting shutdown (init 0)??

Thu Aug 02, 2012 3:19 pm

Since the PI lacks an on off switch I was thinking of creating an electronic power on / off circuit instead.
I would push a button to start the PI and the 5v rails from the USB port would prevent the switch from turning off.
Then when the PI goes into shutdown mode and kills power to the USB port the power supply switch is also killed as a result.
The problem I am facing is when the PI shuts down the USB port is still providing 5v and therefore my switch isn't turning off.

Is there a way to detect whether the PI has actually powered down??

Richard S.

User avatar
RaTTuS
Posts: 10565
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Detecting shutdown (init 0)??

Thu Aug 02, 2012 3:25 pm

use a photodiode to check the power led ? ;-p
or
http://www.thebox.myzen.co.uk/Workshop/LED_Sensing.html
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Detecting shutdown (init 0)??

Thu Aug 02, 2012 3:42 pm

That won't work since the pwr light is still on even when the PI is in shutdown mode.
I think I'll hack the composite video port it gives me 0.9v with video and 0.0v without. :)

Richard S.

User avatar
vladb
Posts: 26
Joined: Mon Jan 16, 2012 4:06 pm

Re: Detecting shutdown (init 0)??

Wed Sep 26, 2012 1:18 pm

Did you manage to do it with the video port?
I'm trying to detect the same thing with an arduino.
http://electronics.stackexchange.com/qu ... dd-without

sharix
Posts: 200
Joined: Thu Feb 16, 2012 11:29 am
Location: Slovenia

Re: Detecting shutdown (init 0)??

Thu Sep 27, 2012 9:36 am

arduino should detect the 0.9V change with no problems.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Detecting shutdown (init 0)??

Sat Sep 29, 2012 11:23 am

I have knocked up a basic circuit last night which can be used to detect the presence of the video signal and thus determine whether the PI is active or in shutdown mode.
I haven't had time to refine component values, however I am happy to say that this works for me and has been designed not to interfere with the video output if connected to a TV.

Image

The circuit takes the video output and feeds this into a 100k resistor, D1 levels off the maximum voltage output to about 0.65 and the signal is then amplified with 2 Class A pre-amps.
D2 + D3 and the 100uF capacitor act as a tank circuit so when there is noise (50 / 60Hz synch signal) the capacitor starts to charge up.
Tr3 and Tr4 are wired up as a transistor schmitt trigger circuit the LED will activate once the voltage in the capacitor gets to point that turns on the trigger.
When there is no signal the 2 100k resistors around the capacitor will gradually cause it to discharge and thus the schmitt trigger will eventually turn itself off.
C1 and C2 are smoothing capacitors they're probably not required but I always like to smooth the power rails.

Richard S.

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

Re: Detecting shutdown (init 0)??

Sat Sep 29, 2012 11:47 am

This seems to only include the ability to detect if the RPi is on or off. do you have the complete circuit that includes the switch? Would be an interesting project.
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Detecting shutdown (init 0)??

Sat Sep 29, 2012 11:54 am

Talk to @boeeerb on twitter - he sussed out which GPIO pins changes state when in init0 - and then you can wire from it back to your switch :)

regards

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

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

Re: Detecting shutdown (init 0)??

Sat Sep 29, 2012 12:08 pm

Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Detecting shutdown (init 0)??

Tue Oct 30, 2012 4:39 pm

After having some spare time on my hands I redesigned my PI smart power supply switch and reduce the component count considerably. :)
I've also added a power down switch not that it's really a requirement but I guess if you're too lazy to pull the plug this might come in handy.
Killing the power should only be done as a last resort since it increases the possibility of a corrupted / unbootable file system.
While other relay circuits already exist as mentioned in this thread they cannot handle situations such as a system reboot because the UART TX output goes low for a split second.

Image

When the relay is off 5v travels down the relay switch via a 22k resistor to charge the 220uF capacitor.
Once there is sufficient voltage this turns on transistors Tr1 and Tr2 (Darlington Pair) to power up the relay.
When the Power On switch makes contact the relay circuit fires up instantly and the capacitor gradually discharges.
By then the voltage output from the GIPO UART TX pin should take over the role of keeping the capacitor charged up.
If however the GIPO UART TX goes low i.e. a power down then the capacitor would discharge and eventual the relay shuts down.

Richard S.

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

Re: Detecting shutdown (init 0)??

Tue Oct 30, 2012 5:28 pm

Cool... Might give this a shot.
Dweeber A.K.A. Kevin...
My RPI Info Pages including Current Setup - http://rpi.tnet.com

shawaj
Posts: 113
Joined: Wed Oct 03, 2012 3:36 am

Re: Detecting shutdown (init 0)??

Thu Nov 01, 2012 1:56 pm

does this switch in diagram need to be an SPDT push switch? or can it be a tact switch?

thanks
Support The MagPi by purchasing printed copies from one of our retailers - http://themagpi.com/en/buy

Please share with anyone who is interested!

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Detecting shutdown (init 0)??

Thu Nov 01, 2012 6:57 pm

They're tactile push button switches they should make electrical contact when pressure is applied.

e.g.
Image

You could use SPDT push switches but that's not necessary since only one "throw" is actually used.

Richard S.

shawaj
Posts: 113
Joined: Wed Oct 03, 2012 3:36 am

Re: Detecting shutdown (init 0)??

Fri Jan 04, 2013 3:23 pm

Hi,

I have had some time now to give this a try, but am still experiencing some issues.

Have you got this circuit to work successfully?

I was thinking about it, and will this not always be powered on?

The current will go through the relay then the 22K resistor then the 10K resistor then it will power on the transistors which will make the relay switch and you will have the 5V directly at the output without pressing the button?

Or am I thinking about how transistors work the wrong way? Or missing something else maybe?

Thanks a lot
Support The MagPi by purchasing printed copies from one of our retailers - http://themagpi.com/en/buy

Please share with anyone who is interested!

Peter247
Posts: 56
Joined: Wed Nov 21, 2012 12:29 am

Re: Detecting shutdown (init 0)??

Fri Jan 04, 2013 4:56 pm

So if I have it right you are using the uart to detect for shut down ?
Does that leave a usable uart port ?
http://www.peter224722.blogspot.co.uk/

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Detecting shutdown (init 0)??

Fri Jan 04, 2013 7:15 pm

@shawaj it does work I've tried and tested it many times before posting the circuit diagram there wouldn't much point if it was just theoretical. :)

What problems are you having is the relay not working??

@Peter247 the circuit has a long delay from when UART TX pin goes from high (3.3v) to low (0v).
Providing UART communications doesn't keep the TX pin low to too long 3 or more seconds then you should be okay.
If you need a longer delay just replace the 220uF with something a little bigger.

Richard S.

CharlieH
Posts: 2
Joined: Thu Dec 27, 2012 10:57 pm
Location: Ithaca, NY USA

Re: Detecting shutdown (init 0)??

Sat Jan 12, 2013 11:37 pm

As an alternative to using a circuit with a relay in it I've been using a circuit found on this page:

http://www.mosaic-industries.com/embedd ... wer-switch

I'm using the circuit identified by "Driving capacitive loads" between a 7.4v LiPo battery and a switch mode power supply with the resulting 5v connected to pins 2 and 4 of the 26-pin connector. This works very well and only needs one push button to power the Pi on and off. Another nice thing about this circuit is that you can put an NPN transistor (e.g. 2N3904) or an N-channel FET (e.g. 2N7000) in parallel with the switch and use it to turn off the power although I haven't done this yet. I've been thinking of monitoring the console's serial output for "Power down." with a PIC and then turning on the transistor to shut of the Pi's power.

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Detecting shutdown (init 0)??

Sat May 04, 2013 9:18 am

I assume that this article was posted later, but here's a design tailored specifically to the Pi:
http://www.mosaic-industries.com/embedd ... controller

wwwill
Posts: 1
Joined: Thu Nov 17, 2016 1:56 am

Re: Detecting shutdown (init 0)??

Thu Nov 17, 2016 2:01 am

Hi Redhawk, have you setup anything special ?
On the RPI3 with the last Raspbian with Pixel, the voltage on TX is variable and definitely not 3.3V.
I set up with a diode and a 220uF, when I power my Pi, it goes from 3.3V to lower and lower with time. Almost zero. RPI still functionning.
Did they change the way TX works in the last 3 years ?
Thanks

[Edit] I found the answer. On the RPI3, the UART is used by the Bluetooth module.
To set it back to its previous behaviour, I added "dtoverlay=pi3-disable-bt" to the /boot/config.txt file.
It works as expected.

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