GuppyHJD
Posts: 26
Joined: Sat Jan 20, 2018 3:37 am

Confused - how to safely shutdown RaspPi 3b+

Tue Feb 18, 2020 3:11 am

Hello,
I have a Raspberry Pi 3 B+. I have a Python script/program that is working doing some basic ping and logging. The script/program blinks LED as designed. I have created a project board that snaps on the 40 pin headers.
I have two more tasks I need to figure out
1) have the python program start when the Raspberry Pi boots
2) put a push-button switch on the board that will properly shutdown the Raspberry Pi and turn off the LED I installed on the project board.

What is confusing is the thousands of posts in this forum with conflicting ways to shutdown the Raspberry Pi.
I see use GPIO pin 23 and on other posts I see use GPIO 26. I do not want to learn by destroying my first Raspberry Pi
In some posts it appears that providing GPIO 2? pin to ground will shut down the device. In others it appears that I should use a sudo shutdown -h now command. Other places I am seeing os.system commands.

Suggestions on how I can correctly research to know if I am going in the right direction?
Thank you

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

Re: Confused - how to safely shutdown RaspPi 3b+

Tue Feb 18, 2020 3:16 am

pin 2 is 5v, do not connect that directly to ground.
What you are referencing is probably the shutdown dt overlay which you add to config. txt and then short pins 5 and 6
55:55:44:44:4C
52:4C:52:42:41

User avatar
rpdom
Posts: 16734
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Confused - how to safely shutdown RaspPi 3b+

Tue Feb 18, 2020 7:45 am

Imperf3kt wrote:
Tue Feb 18, 2020 3:16 am
pin 2 is 5v, do not connect that directly to ground.
What you are referencing is probably the shutdown dt overlay which you add to config. txt and then short pins 5 and 6
GPIO2 is pin 3. Not 5V. I think GuppyHJD is thinking about GPIO3 which IS pin 5.
Unreadable squiggle

PiLabs
Posts: 12
Joined: Sat Jan 18, 2020 10:34 pm
Contact: YouTube

Re: Confused - how to safely shutdown RaspPi 3b+

Tue Feb 18, 2020 8:36 pm

Run this in terminal:

Code: Select all

sudo poweroff
I love raspberry pi and Windows 95 and Macintosh

GuppyHJD
Posts: 26
Joined: Sat Jan 20, 2018 3:37 am

Re: Confused - how to safely shutdown RaspPi 3b+

Tue Feb 18, 2020 9:00 pm

PiLabs,
Thank you.
I will not have a keyboard or screen connected to the Pi, so I am looking for the safe way to shutdown the pi with a button / switch and any needed Python code.
I currently have a small switch wired to pin 14 (Grnd) and pin 13 (GPIO 27). When I press the switch and hold a few seconds, the screen blanks, the green LED on the Raspberry PI stops blinking. I am thinking the device is shutdown (not 100% sure, it could be asleep?). The only way to turn the RPi back on is to unplug and replug.
I have also considered using pin 39 (Ground) and pin 40 (GPIO 21) but have not tested that.

If this is the right way to shutdown the device, I will put a resister and LED on the project board, that will be on at boot-up and go out when GPIO 27 changes, to show that the device is now turned off.

Does anybody know why Raspberry Pi does not design in or make a pin set for power shutdown/control?
Henry

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

Re: Confused - how to safely shutdown RaspPi 3b+

Tue Feb 18, 2020 9:38 pm

GuppyHJD wrote:
Tue Feb 18, 2020 9:00 pm
PiLabs,
Thank you.
I will not have a keyboard or screen connected to the Pi, so I am looking for the safe way to shutdown the pi with a button / switch and any needed Python code.
I currently have a small switch wired to pin 14 (Grnd) and pin 13 (GPIO 27). When I press the switch and hold a few seconds, the screen blanks, the green LED on the Raspberry PI stops blinking. I am thinking the device is shutdown (not 100% sure, it could be asleep?). The only way to turn the RPi back on is to unplug and replug.
I have also considered using pin 39 (Ground) and pin 40 (GPIO 21) but have not tested that.

If this is the right way to shutdown the device, I will put a resister and LED on the project board, that will be on at boot-up and go out when GPIO 27 changes, to show that the device is now turned off.

Does anybody know why Raspberry Pi does not design in or make a pin set for power shutdown/control?
Henry
On power off look for the ACT LED flash 10 times.

As already mentioned above, another option is: you can make a startup / shutdown button without the need for a running script by adding this to /boot/config.txt:

Code: Select all

dtoverlay=gpio-shutdown
This will allow you to have start and shutdown function using a single momentary type switch.

The default pin for the above is pin 5 (GPIO3).

If you plan to use I2C then you will need to change the shutdown pin to something else.
For example to change the shutdown pin from the default GPIO 3 to GPIO 26 (physical pin 37), add this to /boot/config.txt

Code: Select all

dtoverlay=gpio-shutdown,gpio_pin=26
However you can't change the startup pin from GPIO 3 (physical pin 5). That always works regardless.
So changing from default will require 2 buttons.
Or you can use the RUN header to start.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

GuppyHJD
Posts: 26
Joined: Sat Jan 20, 2018 3:37 am

Re: Confused - how to safely shutdown RaspPi 3b+

Wed Feb 19, 2020 3:04 am

klricks
I modified my config.txt file.
I have pin 5 (GPIO 3) available on my board. Can I connect the pushbutton switch between pin 14 (ground) and pin 5 (GPIO 3)?
Thank you

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

Re: Confused - how to safely shutdown RaspPi 3b+

Wed Feb 19, 2020 3:22 am

GuppyHJD wrote:
Wed Feb 19, 2020 3:04 am
klricks
I modified my config.txt file.
I have pin 5 (GPIO 3) available on my board. Can I connect the pushbutton switch between pin 14 (ground) and pin 5 (GPIO 3)?
Thank you
Any ground can be used. Pin 6 would be the most convenient if not used for anything else.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

PiLabs
Posts: 12
Joined: Sat Jan 18, 2020 10:34 pm
Contact: YouTube

Re: Confused - how to safely shutdown RaspPi 3b+

Fri Mar 27, 2020 8:32 pm

You can do this:

Code: Select all

import os
os.system("sudo poweroff")
I love raspberry pi and Windows 95 and Macintosh

Return to “Beginners”