Chandru42
Posts: 18
Joined: Fri Apr 13, 2018 7:23 am

Power on / off button for Pi

Thu Jul 05, 2018 7:57 am

Hello everyone,

I came across many articles to make a simple power on 7 off button for raspberry pi by connecting GPIO 3 and ground.

https://scribles.net/adding-power-switc ... pberry-pi/

https://howchoo.com/g/mwnlytk3zmm/how-t ... spberry-pi

I have also tried this and it works very well. But the problem is i am also using Adafruit ADS1015 analog to digital converter in my circuit which uses the GPIO 3(scl) for establishing i2c connection. It is not working when both are connected together.

i would like to know is is possible to use other GPIO pin to make this both working ? Or is there any other solution available?

wolf.z
Posts: 135
Joined: Thu Dec 24, 2015 8:34 pm

Re: Power on / off button for Pi

Thu Jul 05, 2018 11:10 am

This issue has been discussed many times. The "off" functionality is easily moved to anther GPIO pin. It is controlled by a script as from linked example. The wakeup functionality is controlled by a binary system file. So pin5 appears to carry a hardwired function in means of wakeup (unless someone changes that file?)

The functionality you are using is not a true on/off. Rather, the Pi starts to boot after a halt command until the point waiting for pin5 to get enabled in a low power state. If depowered-repowered, the Pi will not wait for Pin5 enabled.
Thus, you could change to the situation
- halt-by-pushbutton on any GPIO
- boot by depower-repower.

Both actions on one pin is stuck to pin5.

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

Re: Power on / off button for Pi

Thu Jul 05, 2018 12:45 pm

You can make a shutdown button without the need for a running script by adding this to /boot/config.txt:

Code: Select all

dtoverlay=gpio-shutdown
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.

Chandru42
Posts: 18
Joined: Fri Apr 13, 2018 7:23 am

Re: Power on / off button for Pi

Fri Jul 06, 2018 10:38 am

klricks wrote:
Thu Jul 05, 2018 12:45 pm
You can make a shutdown button without the need for a running script by adding this to /boot/config.txt:

Code: Select all

dtoverlay=gpio-shutdown
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.
Thank you somuch.This helps me a lot. Also , Do you have any idea of how to power on the raspberry pi using a switch or button without removing the power supply and connecting it every time?

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

Re: Power on / off button for Pi

Fri Jul 06, 2018 12:08 pm

Chandru42 wrote:
Fri Jul 06, 2018 10:38 am
.... Also , Do you have any idea of how to power on the raspberry pi using a switch or button without removing the power supply and connecting it every time?
Use a multi outlet power strip with a power button.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Chandru42
Posts: 18
Joined: Fri Apr 13, 2018 7:23 am

Re: Power on / off button for Pi

Fri Jul 06, 2018 1:37 pm

klricks wrote:
Fri Jul 06, 2018 12:08 pm
Chandru42 wrote:
Fri Jul 06, 2018 10:38 am
.... Also , Do you have any idea of how to power on the raspberry pi using a switch or button without removing the power supply and connecting it every time?
Use a multi outlet power strip with a power button.
Thank you!

Gautamk
Posts: 39
Joined: Fri Jun 01, 2018 6:14 pm

Re: Power on / off button for Pi

Fri Jul 06, 2018 7:54 pm

klricks wrote:
Thu Jul 05, 2018 12:45 pm
You can make a shutdown button without the need for a running script by adding this to /boot/config.txt:

Code: Select all

dtoverlay=gpio-shutdown
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.
Hello, i am using RPi Zero W but i don't know which GPIO pin i use for shutdown and power on functions can you please guide me?

petrockblog
Posts: 272
Joined: Wed Jul 04, 2012 6:12 am
Location: Germany
Contact: Website

Re: Power on / off button for Pi

Mon Nov 11, 2019 10:02 pm

The PowerBlock (powerblock.petrockblock.com) or the PowerBlockling (https://petrockblock.com/powerblockling) also might be just what you are looking for.
fun stuff for technics enthusiasts: www.petrockblock.com

Bope
Posts: 57
Joined: Sat Jul 06, 2019 2:57 am

Re: Power on / off button for Pi

Mon Nov 11, 2019 11:15 pm

Isn’t that powerblocking button still using GPIO 3?

Gautama, everything in this thread also pertains to your pi zero. Using the GPIO pins does not actually power up/down your pi, it just puts it in standby mode. To actually shutdown your pi go to the menu and select shutdown. When complete unplug the power supply. To boot plug the power supply back in.

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

Re: Power on / off button for Pi

Mon Nov 11, 2019 11:35 pm

Chandru42 wrote:
Fri Jul 06, 2018 1:37 pm
klricks wrote:
Fri Jul 06, 2018 12:08 pm
Chandru42 wrote:
Fri Jul 06, 2018 10:38 am
.... Also , Do you have any idea of how to power on the raspberry pi using a switch or button without removing the power supply and connecting it every time?
Use a multi outlet power strip with a power button.
Thank you!
Any reason to not simply momentarily short RUN to GND?
Your regular x86 PC works the same way, turning it off doesn't actually turn it off and shorting a certain pin to ground wakes the PC from its halt state.
55:55:44:44:4C
52:4C:52:42:41

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

Re: Power on / off button for Pi

Tue Nov 12, 2019 9:16 am

Bope wrote:
Mon Nov 11, 2019 11:15 pm
Using the GPIO pins does not actually power up/down your pi, it just puts it in standby mode. To actually shutdown your pi go to the menu and select shutdown.
If the gpio_poweroff option is set, then shorting GPIO3 (pin 5) to ground/0V is exactly the same as the shutdown command. Both shutdown the OS and go into a low-power halt state.

To restart from that state you can disconnect/reconnect the power, connect the RUN connection to ground/0V or short GPIO3 to ground/0V again (on the Pi 4 you'll need to enable an option in the boot eeprom code to do that).
Unreadable squiggle

deepo
Posts: 552
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Power on / off button for Pi

Tue Nov 12, 2019 10:03 am

rpdom wrote:
Tue Nov 12, 2019 9:16 am
Bope wrote:
Mon Nov 11, 2019 11:15 pm
Using the GPIO pins does not actually power up/down your pi, it just puts it in standby mode. To actually shutdown your pi go to the menu and select shutdown.
If the gpio_poweroff option is set, then shorting GPIO3 (pin 5) to ground/0V is exactly the same as the shutdown command. Both shutdown the OS and go into a low-power halt state.

To restart from that state you can disconnect/reconnect the power, connect the RUN connection to ground/0V or short GPIO3 to ground/0V again (on the Pi 4 you'll need to enable an option in the boot eeprom code to do that).
gpio_poweroff is not what you think:
http://www.embeddedpi.com/documentation ... -gpio-line

Code: Select all

Name:   gpio-poweroff
Info:   Drives a GPIO high or low on poweroff (including halt)
Load:   dtoverlay=gpio-poweroff,=
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.
/Mogens

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

Re: Power on / off button for Pi

Tue Nov 12, 2019 10:49 am

deepo wrote:
Tue Nov 12, 2019 10:03 am
gpio_poweroff is not what you think:
Apologies. I got the wrong option.

gpio-shutdown is the one I was thinking of.
Unreadable squiggle

alphanumeric
Posts: 2480
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Power on / off button for Pi

Tue Nov 12, 2019 12:46 pm

For me on my Pi 4B, if I enable i2c and reboot the dtoverlay=gpio-shutdown stops working. Pressing my button does nothing. Disable it and reboot and its working again. It still boots up when GPIO 3 in grounded.

alphanumeric
Posts: 2480
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Power on / off button for Pi

Tue Nov 12, 2019 1:02 pm

If I want to set an alternate GPIO say physical pin 11 is it as follows?
dtoverlay=gpio-shutdown,gpio_pin=11
And do I have to also set the pullup etc?
dtoverlay=gpio-shutdown,gpio_pin=11,active_low=1,gpio_pull=up

EDIT: neither one of the above works? I have i2c turned off again.
I have a fan shim which has a button wired to BCM 17 physical pin 11.

https://pinout.xyz/pinout/fan_shim#

EDIT: 2 dtoverlay=gpio-shutdown works with the fan shim button via GPIO 3 no problem. Until I enable i2c, which is an interface I use a quit often.

deepo
Posts: 552
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Power on / off button for Pi

Tue Nov 12, 2019 5:18 pm

alphanumeric wrote:
Tue Nov 12, 2019 1:02 pm
If I want to set an alternate GPIO say physical pin 11 is it as follows?
dtoverlay=gpio-shutdown,gpio_pin=11
And do I have to also set the pullup etc?
dtoverlay=gpio-shutdown,gpio_pin=11,active_low=1,gpio_pull=up

EDIT: neither one of the above works? I have i2c turned off again.
I have a fan shim which has a button wired to BCM 17 physical pin 11.

https://pinout.xyz/pinout/fan_shim#

EDIT: 2 dtoverlay=gpio-shutdown works with the fan shim button via GPIO 3 no problem. Until I enable i2c, which is an interface I use a quit often.
gpio_pin is actually not referring to pin numbers, but GPIO numbers (BCM numbers). Pin 11 is GPIO17, so try with gpio_pin=17

/Mogens

alphanumeric
Posts: 2480
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Power on / off button for Pi

Tue Nov 12, 2019 7:09 pm

Thanks for that,

Code: Select all

dtoverlay=gpio-shutdown,gpio_pin=17,active_low=1,gpio_pull=up  
worked. :D
Even works if i2c is enabled which is what I wanted. :D
I could have sworn I had tried that but I guess I didn't? Or I made a typo? Sorted now though.

danduran31
Posts: 1
Joined: Tue Dec 10, 2019 1:48 pm

Re: Power on / off button for Pi

Tue Dec 10, 2019 1:59 pm

alphanumeric:

Could you please send the exact complete code using GPIO17 for the button. Im using 12C on my raspberry too.

alphanumeric
Posts: 2480
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Power on / off button for Pi

Tue Dec 10, 2019 8:27 pm

Open a terminal window and run the following

Code: Select all

sudo nano /boot/config.txt 
Then add the following line.

Code: Select all

dtoverlay=gpio-shutdown,gpio_pin=17,active_low=1,gpio_pull=up
ctrl + x, y enter, and reboot, done deal.

JeffZ123
Posts: 17
Joined: Sun Aug 12, 2018 3:43 pm

Re: Power on / off button for Pi

Tue Dec 17, 2019 3:30 pm

alphanumeric wrote:
Tue Dec 10, 2019 8:27 pm
Open a terminal window and run the following

Code: Select all

sudo nano /boot/config.txt 
Then add the following line.

Code: Select all

dtoverlay=gpio-shutdown,gpio_pin=17,active_low=1,gpio_pull=up
ctrl + x, y enter, and reboot, done deal.
...
Confirmed this solution is working for me as well with one switch for wake/halt and an IC2 display.

Enabling the display no longer shuts down the pi :P

Return to “Beginners”