mangiari
Posts: 40
Joined: Sun Mar 11, 2018 4:45 pm

How to detect shutdown state?

Tue Jan 01, 2019 7:19 pm

Is there an easy clean way to get a signal (preferably a low on an else wise high gpio pin) when a raspberry pi halted completely and is safe to be cut off from the power supply? I found this power led tutorial but the serial pins don't seem to be a solid on/off indicator when it comes to switching logic (not only led status light).

Is there a way to tell the raspberry pi it should set a specific gpio pin (one of the lower 8 ones) to be low, when the raspberry pi reaches save halt state? At east gpio4 stays at 3,3V even after the raspberry pi is shut down.

klricks
Posts: 8198
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA

Re: How to detect shutdown state?

Tue Jan 01, 2019 7:50 pm

mangiari wrote:
Tue Jan 01, 2019 7:19 pm
Is there an easy clean way to get a signal (preferably a low on an else wise high gpio pin) when a raspberry pi halted completely and is safe to be cut off from the power supply? I found this power led tutorial but the serial pins don't seem to be a solid on/off indicator when it comes to switching logic (not only led status light).

Is there a way to tell the raspberry pi it should set a specific gpio pin (one of the lower 8 ones) to be low, when the raspberry pi reaches save halt state? At east gpio4 stays at 3,3V even after the raspberry pi is shut down.
I believe the overlay gpio-poweroff can do that.
For information see: /boot/overlays/README
Unless specified otherwise my response is based on the latest and fully updated RPi OS Bullseye w/ Desktop OS.

mangiari
Posts: 40
Joined: Sun Mar 11, 2018 4:45 pm

Re: How to detect shutdown state?

Tue Jan 01, 2019 10:20 pm

Hey thanks, that's exactly what I'm looking for. After your hint, I found this Thread about the same issue and questions, which helps a lot!

I added

Code: Select all

dtoverlay=gpio-poweroff,gpiopin=4,active_low=1
to my /boot/config.txt and gpio4 now goes high at the moment I connect the USB and it goes back to low after I trigger a shutdown from the software. Exactly what I was looking for.

It has some side effects, looks like some other stuff is not as much powered down as in the default behavior. The onboard led does not go dark any more and also the usb sound card I use, continues to have both LEDs on, formerly they got dark after shutdown. Well, I anyhow want to remove the power from the raspberry, so I do not care what it is doing with the LEDs...

User avatar
Milliways
Posts: 770
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: How to detect shutdown state?

Tue Jan 01, 2019 11:22 pm

mangiari wrote:
Tue Jan 01, 2019 10:20 pm
Hey thanks, that's exactly what I'm looking for. After your hint, I found this Thread about the same issue and questions, which helps a lot!

I added

Code: Select all

dtoverlay=gpio-poweroff,gpiopin=4,active_low=1
to my /boot/config.txt and gpio4 now goes high at the moment I connect the USB and it goes back to low after I trigger a shutdown from the software. Exactly what I was looking for.

It has some side effects, looks like some other stuff is not as much powered down as in the default behavior. The onboard led does not go dark any more and also the usb sound card I use, continues to have both LEDs on, formerly they got dark after shutdown. Well, I anyhow want to remove the power from the raspberry, so I do not care what it is doing with the LEDs...
On the Pi3B+ (and probably the 3A+) there is a PEN (Power ENable) header which can be used to power down the regulator.

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

Re: How to detect shutdown state?

Wed Jan 02, 2019 3:26 am

Milliways wrote:
Tue Jan 01, 2019 11:22 pm
On the Pi3B+ (and probably the 3A+) there is a PEN (Power ENable) header which can be used to power down the regulator.
The Pi3A+ doesn't have the 4-pin header with that. It's part of the PoE pins...and the Pi3A+ doesn't have anything related to Ethernet.

User avatar
Milliways
Posts: 770
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: How to detect shutdown state?

Wed Jan 02, 2019 5:05 am

W. H. Heydt wrote:
Wed Jan 02, 2019 3:26 am
Milliways wrote:
Tue Jan 01, 2019 11:22 pm
On the Pi3B+ (and probably the 3A+) there is a PEN (Power ENable) header which can be used to power down the regulator.
The Pi3A+ doesn't have the 4-pin header with that. It's part of the PoE pins...and the Pi3A+ doesn't have anything related to Ethernet.
It is NOT a 4 pin header - there are 2 solder pads to mount a header for RUN & PEN. On earlier models there is a (more useful) RUN & GND for reset.

mangiari
Posts: 40
Joined: Sun Mar 11, 2018 4:45 pm

Re: How to detect shutdown state?

Thu Jan 03, 2019 1:56 am

As I mentioned, for my personal project the behavior after shutdown is not relevant, as soon as this shutdown GPIO-Pin goes low, the MOSFET will switch off the power from the raspberry pi. And it's a zero 1.3 in my case.

mangiari
Posts: 40
Joined: Sun Mar 11, 2018 4:45 pm

Re: How to detect shutdown state?

Fri Jan 04, 2019 12:56 am

Unfortunately the setup as I tried it does not work. The configured GPIO-pin goes low after shutdown, it was the one that holds the MOSFET active, so that the raspberry had power, but at the moment the power is disconnected (actually just the negative power supply gets a high resistor against the real ground), the 5V still connected to the positive power supply seem to find their way to that GPIO pin again. Looks like the pin is actively pulled down and as soon as the power supply is gone, that pulling down does not work any more.

So at the moment the MOSFET takes away the ground, the MOSFET already gets voltage again and restarts the pi. I'm close to build in a relay with full disconnection of the power supply. But this will eat an awful amount of power as long as the pi runs. Typical relay eats half the current than the pi does :?

pfletch101
Posts: 671
Joined: Sat Feb 24, 2018 4:09 am
Location: Buffalo, NY, USA

Re: How to detect shutdown state?

Fri Jan 04, 2019 10:24 pm

mangiari wrote:
Fri Jan 04, 2019 12:56 am
Unfortunately the setup as I tried it does not work. The configured GPIO-pin goes low after shutdown, it was the one that holds the MOSFET active, so that the raspberry had power, but at the moment the power is disconnected (actually just the negative power supply gets a high resistor against the real ground), the 5V still connected to the positive power supply seem to find their way to that GPIO pin again. Looks like the pin is actively pulled down and as soon as the power supply is gone, that pulling down does not work any more.

So at the moment the MOSFET takes away the ground, the MOSFET already gets voltage again and restarts the pi. I'm close to build in a relay with full disconnection of the power supply. But this will eat an awful amount of power as long as the pi runs. Typical relay eats half the current than the pi does :?
Why are you disconnecting the ground, rather than the 'live' power rail? Under most circumstances it wouldn't matter - a broken circuit is a broken circuit - but here you would seem to be asking for exactly the problem you are seeing. Within a short time of disconnecting the ground from a circuit (while leaving the live power rail connected), I would expect any point on the circuit to rise to the potential of the power rail, provided that a very high impedance 'sensor' was used to measure that potential. The input of a MOSFET has, of course, a very high impedance!

mangiari
Posts: 40
Joined: Sun Mar 11, 2018 4:45 pm

Re: How to detect shutdown state?

Tue Jan 08, 2019 4:23 pm

If you don't have the raspberry pi in the positive side of the MOSFET, it will not be able to switch the MOSFET active. The raspberry pi needs to have potential above the source potential of the MOSFET to be able to drive it active. The same problem occurs when using bipolar transistors as switch.

But now I have a completly different approach, which will solve all that: optocouplers...

Return to “Advanced users”