DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Rpi 3 Shutdown button

Sun Nov 12, 2017 11:27 am

HI,

I find it very strange that i can find so little info the most elementary of things :
Provide a on/off button with script to my Rpi.

So the RPi is out there, performing it's functions (handheld), and now it's time to stop.
What i would like:
There is a switch (tumbler?) that says on/off, it "breaks" the basic python while loop and
launches the command "sudo shutdown -h now".

Or is it so simple that nobody bothers to talk about it.

What makes me think it is not that simple, is that i saw a tumbler switch (somewhere?) with a little PCB attached,
that did just that, i think.

Question: which is the state of the art way to go?

thx,
Paul

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

Re: Rpi 3 Shutdown button

Sun Nov 12, 2017 11:46 am

DPaul wrote:
Sun Nov 12, 2017 11:27 am
So the RPi is out there, performing it's functions (handheld)...
Is it running from battery? (explanation why asking this comes later)
DPaul wrote:
Sun Nov 12, 2017 11:27 am
... and now it's time to stop.
What i would like:
There is a switch (tumbler?) that says on/off, it "breaks" the basic python while loop and
launches the command "sudo shutdown -h now".

Or is it so simple that nobody bothers to talk about it.

What makes me think it is not that simple, is that i saw a tumbler switch (somewhere?) with a little PCB attached,
that did just that, i think.

Question: which is the state of the art way to go?
There exists many approaches by attching a (physical) button to a GPIO, it will be configured as input, and initiate the shutdown-sequence, if button is pressed. There is also an overlay provided yet, which may cover this function, but I haven't tested until now ... (See '/boot/overlay/README.*' for more information.)

But be aware, that this doesn't disconnect your battery, so it may be drained empty even if in shutdown-state! To avoid this, additional circuits are needed. There exists additional boards, for this purpose, if you do not want to build it by yourself ...

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!

User avatar
scruss
Posts: 2272
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Rpi 3 Shutdown button

Sun Nov 12, 2017 1:52 pm

DPaul wrote:
Sun Nov 12, 2017 11:27 am
I find it very strange that i can find so little info the most elementary of things :
Provide a on/off button with script to my Rpi.
I wrote this, but some people like it: Combined Restart / Shutdown Button for Raspberry Pi

If you want power physically disconnected, you'll need something like Pimoroni's OnOff shim. It uses some fixed GPIO assignments, so may not work for you.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

beta-tester
Posts: 1235
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Rpi 3 Shutdown button

Sun Nov 12, 2017 2:19 pm

as FM_81 told... see /boot/overlays/README

Code: Select all

Name:   gpio-poweroff
Info:   Drives a GPIO high or low on poweroff (including halt). Enabling this
        overlay will prevent the ability to boot by driving GPIO3 low.
Load:   dtoverlay=gpio-poweroff,<param>=<val>
Params: gpiopin                 GPIO for signalling (default 26)

        active_low              Set if the power control device requires a
                                high->low transition to trigger a power-down.
                                Note that this will require the support of a
                                custom dt-blob.bin to prevent a power-down
                                during the boot process, and that a reboot
                                will also cause the pin to go low.


Name:   gpio-shutdown
Info:   Initiates a shutdown when GPIO pin changes. The given GPIO pin
        is configured as an input key that generates KEY_POWER events.
        This event is handled by systemd-logind by initiating a
        shutdown. Systemd versions older than 225 need an udev rule
        enable listening to the input device:

                ACTION!="REMOVE", SUBSYSTEM=="input", KERNEL=="event*", \
                        SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", \
                        ATTRS{keys}=="116", TAG+="power-switch"

        This overlay only handles shutdown. After shutdown, the system
        can be powered up again by driving GPIO3 low. The default
        configuration uses GPIO3 with a pullup, so if you connect a
        button between GPIO3 and GND (pin 5 and 6 on the 40-pin header),
        you get a shutdown and power-up button.
Load:   dtoverlay=gpio-shutdown,<param>=<val>
Params: gpio_pin                GPIO pin to trigger on (default 3)

        active_low              When this is 1 (active low), a falling
                                edge generates a key down event and a
                                rising edge generates a key up event.
                                When this is 0 (active high), this is
                                reversed. The default is 1 (active low).

        gpio_pull               Desired pull-up/down state (off, down, up)
                                Default is "up".

                                Note that the default pin (GPIO3) has an
                                external pullup.
{ I only give negative feedback }
RPi Model B (rev1, 256MB) & B (rev2, 512MB) & B+, RPi2B, RPi3B, RPi3B+, RPiZeroW, ...

DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Re: Rpi 3 Shutdown button

Sun Nov 12, 2017 3:49 pm

OK, it's running from battery!
I need to disconnect the battery too, i understand now;
I'll look into these options,

thx,
Paul

User avatar
scruss
Posts: 2272
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Rpi 3 Shutdown button

Mon Nov 13, 2017 6:31 pm

beta-tester wrote:
Sun Nov 12, 2017 2:19 pm
… Enabling this overlay will prevent the ability to boot by driving GPIO3 low.
Um, this doesn't exactly look like a friendly user shutdown method.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
Imperf3kt
Posts: 2418
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: Rpi 3 Shutdown button

Mon Nov 13, 2017 7:00 pm

scruss wrote:
Mon Nov 13, 2017 6:31 pm
beta-tester wrote:
Sun Nov 12, 2017 2:19 pm
… Enabling this overlay will prevent the ability to boot by driving GPIO3 low.
Um, this doesn't exactly look like a friendly user shutdown method.

That is why you use gpio-shutdown and not gpio-poweroff.
However in my experience, this function only allows you to restart your Pi. It won't shut it down nor boot it the first time.

@OP
Just put a physical switch between the battery and the power input to break the vcc connection after you perform a shutdown. (wait about 10 seconds)
Google is ubiquitous - Try it today, it's free!
https://opensource.com/life/16/10/how-ask-technical-questions

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

Re: Rpi 3 Shutdown button

Mon Nov 13, 2017 7:32 pm

Imperf3kt wrote:
Mon Nov 13, 2017 7:00 pm
Just put a physical switch between the battery and the power input to break the vcc connection after you perform a shutdown. (wait about 10 seconds)
OK, one can do it in this way, of course!
But it's not much elegant: You always have to do TWO actions at the end. One for shutdown and one for disconnect battery. And you have to do these in a correct timing ...

Best Regards, 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!

RonR
Posts: 298
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Rpi 3 Shutdown button

Mon Nov 13, 2017 8:51 pm

Imperf3kt wrote:
Mon Nov 13, 2017 7:00 pm
That is why you use gpio-shutdown and not gpio-poweroff.
However in my experience, this function only allows you to restart your Pi. It won't shut it down nor boot it the first time.
FWIW, I've been using 'dtoverlay=gpio-shutdown' in /boot/config.txt with a pushbutton switch connected between GPIO header pins 5 and 6 for many months now and it's been 100% reliable. Pushing the button when the system is running does a 'shutdown -h now' and pushing the button when the system is halted causes it to boot. As others have stated, it doesn't remove power from the RPi, but it does reliably halt and restart it.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Rpi 3 Shutdown button

Tue Nov 14, 2017 3:43 am

any info what current we talk about? ( in HALT state )

beta-tester
Posts: 1235
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Rpi 3 Shutdown button

Tue Nov 14, 2017 3:46 pm

what about buying a UPS HAT/shield for the RPi?
i know, that there are some available.
they have a battery and battery charger. they can shut down the RPi correctly by button/software/automatically at external powerloss
and after shut down, then power off the RPi after a while completely (more or less) - i guess not with a relais, but more than it would be when the RPi is in halt mode.

search for Raspberry PI and UPS.
{ I only give negative feedback }
RPi Model B (rev1, 256MB) & B (rev2, 512MB) & B+, RPi2B, RPi3B, RPi3B+, RPiZeroW, ...

DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Re: Rpi 3 Shutdown button

Tue Nov 14, 2017 4:58 pm

Hi,

I am inclined to repeat what i said in post #1.
Why is it so seemingly difficult ?

To use a (handheld) device, you need to switch it on and then off again.
(Completely off)

I am currently looking at the pimoroni shim:
https://shop.pimoroni.com/collections/e ... onoff-shim

For a beginner all this is very confusing :shock: ;)

Paul.

hippy
Posts: 5373
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Rpi 3 Shutdown button

Tue Nov 14, 2017 5:25 pm

DPaul wrote:
Tue Nov 14, 2017 4:58 pm
Why is it so seemingly difficult ?
Because the Pi was never designed to be used in applications which require battery or power management. It is primarily a turn it on and leave it on device intended to be used with a mains powered PSU.

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

Re: Rpi 3 Shutdown button

Tue Nov 14, 2017 6:20 pm

hippy wrote:
Tue Nov 14, 2017 5:25 pm
Because the Pi was never designed to be used in applications which require battery or power management. It is primarily a turn it on and leave it on device intended to be used with a mains powered PSU.
This is absolutely correct!
But for many people it gives a "special stimulus' to make things that "wasn't planned by the manufacturer". Often they have success, may be sometimes not?

And it is also a fact, that this can give (especially for a beginner) the sentence
DPaul wrote:
Tue Nov 14, 2017 4:58 pm
For a beginner all this is very confusing :shock: ;)
How ever, I assume, the pimoroni-shim should do what you want ... May be, someone own's that (I didn't) and can confirm?

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!

User avatar
scruss
Posts: 2272
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Rpi 3 Shutdown button

Wed Nov 15, 2017 7:01 pm

FM81 wrote:
Tue Nov 14, 2017 6:20 pm
How ever, I assume, the pimoroni-shim should do what you want ... May be, someone own's that (I didn't) and can confirm?
I have an OnOff SHIM, and wrote about it here: Installing the Pimoroni OnOff Shim the hard way. Note that you don't have to install it the way I did.

Plus points:
  • It appears to completely remove power from the board when turned off. It might draw a very tiny current when off, but I haven't metered it
  • It's small
  • It works!
Minus points:
  • It re-routes the power connection off to the side of your Raspberry Pi, so it likely won't fit in existing cases.
  • It uses a couple of fixed GPIO ports, and so won't work with some HATs
  • It doesn't have any charger/battery capabilities
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

DPaul
Posts: 97
Joined: Fri Oct 13, 2017 7:39 am

Re: Rpi 3 Shutdown button

Thu Nov 16, 2017 6:49 am

Very interesting.
About the power switch, i have read that you can solder your own to the board?

If i can find a supplier with reasonable delivery times (like 24 hrs), i'm in :D
Paul

User avatar
scruss
Posts: 2272
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Rpi 3 Shutdown button

Thu Nov 16, 2017 5:12 pm

Yes, the shim has optional breakout pins to connect an external momentary button
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

AstroJohn
Posts: 13
Joined: Mon Feb 25, 2013 7:02 pm

Re: Rpi 3 Shutdown button

Wed Jan 10, 2018 9:51 pm

One point to note is that the software supplied with the Pimoroni OnOffShim does not work with Raspbian Wheezy. I installed it on a Pi B and was confused why it would not install and work.

The power up button part works Ok as that is a hardware function.

After a bit of a struggle I got my Pi to shutdown when the button was operated using part of the supplied software. However this still left the Pi in a partially powered (hibernation state).

I eventually found a way of executing a small script in the final part of the shutdown sequence that killls the power completely. When the Pi enters Init 0 it looks for a scrips to control the UPS power and executes it if it exists. In the normal installation it does not exist but by supplying the UPS script which in my case energises the GPIO pin to kill the power I was able to get a complete power down.

I have never got the green LED to flash as it shuts down but that does not really concern me.

Note if you have the Shim fitted the Pi will not restart after a power failure (assuming the SD Card was not corrupted). To restart it you need to operate the button on the Shim.

Return to “Beginners”