4

I've been doing some research on power buttons for the Raspberry Pi, but I'm having quite a hard time finding information. Right now, I have button working on GPIO5, and when I connect it to the opposing GND pin, the Pi boots up. I added the line dtoverlay=gpio-shutdown to my /boot/config.txt, so that I can shutdown with this connection as well. However, I have a couple of questions that I'm having a hard time finding answers to.

  • Is the shutdown initiated with connecting the GPIO3 pin and the GND pin considered a safe shutdown? Will the system finish writing to memory, etc, just like with sudo shutdown?
  • I know that I can change the pin for shutdown, by changing dtoverlay=gpio-shutdown to dtoverlay=gpio-shutdown,gpio-pin=X, but is there a way to change the pin for boot up as well? Considering GPIO3 is normally used for I2C.
Seamus
  • 18,728
  • 2
  • 27
  • 57
are_end
  • 149
  • 1
  • 1
  • 2

2 Answers2

3

The operation is explained in /boot/overlays/README

It is quite safe, I have it on all my Pi in case I need to shutdown a headless Pi (or one without keyboard attached), although my Pi are rarely shutdown, unless I am adding hardware.

I use dtoverlay=gpio-shutdown,gpio_pin=21 so I can shutdown by bridging pins 39/40

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 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. Please note that
        Raspberry Pi 1 Model B rev 1 uses GPIO1 instead of GPIO3.
Load:   dtoverlay=gpio-shutdown,<param>=<val>
Params: gpio_pin                GPIO pin to trigger on (default 3)
                                For Raspberry Pi 1 Model B rev 1 set this
                                explicitly to value 1, e.g.:

                                    dtoverlay=gpio-shutdown,gpio_pin=1

        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. Same applies for GPIO1
                                on Raspberry Pi 1 Model B rev 1.

        debounce                Specify the debounce interval in milliseconds
                                (default 100)
Milliways
  • 54,718
  • 26
  • 92
  • 182
  • Using `gpio_pin=21`, "bridging pins 39/40", are you able to re-boot your RPi as well as shutting it down? I ask because the OP of [another question](https://raspberrypi.stackexchange.com/q/127604/83790) here claimed he did so. – Seamus Jul 12 '21 at 22:25
  • @Seamus absolutely not. Once shutdown it can only be rebooted by cutting power (or resetting the SOC) although you can use pin 5 unless you use one of the other overlays which disable it. – Milliways Jul 12 '21 at 22:58
  • OK, thanks - I thought so, or at least it didn't work for me. – Seamus Jul 13 '21 at 04:42
  • @Seamus To which "it" are you referring? – Milliways Jul 13 '21 at 04:44
  • "It" being using GPIO 21 to start and stop the RPi. IOW, a single button can start & stop the RPi if it's connected between GPIO 3 and GND, but using GPIO 21 only allows one to stop. – Seamus Jul 13 '21 at 04:50
  • @Seamus I have on all my Pi (and have since Jessie) it "Initiates a shutdown". I concede if the Pi has locked up it may not shutdown. "This overlay only handles shutdown". No documentation mentions reboot. – Milliways Jul 13 '21 at 04:55
  • The ["docs" for the `gpio-shutdown` overlay](https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README) state: `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.` And yeah - AFAIK, using GPIO 3 to start isn't documented anywhere else. – Seamus Jul 13 '21 at 05:03
  • 1
    I agree it is poorly documented. See https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=24682 or https://elinux.org/RPI_safe_mode#Wake_from_Halt.5B1.5D – Milliways Jul 13 '21 at 07:14
3

I see two separate questions re use and configuration of "power buttons" to halt and boot an RPi 4:

Question 1:

Is the shutdown initiated with connecting the GPIO3 pin and the GND pin considered a safe shutdown?

Answer:

Yes - it is a safe shutdown. For details & confirmation, see REF 1 and REF 2.

Question 2:

I know that I can change the pin for shutdown, by changing dtoverlay=gpio-shutdown to dtoverlay=gpio-shutdown,gpio-pin=X, but is there a way to change the pin for boot up as well? Considering GPIO3 is normally used for I2C.

Answer:

Before going any further, I'd like to make sure we're clear on two points:

  • You can startup and shutdown your RPi with a single push-button switch connected between GPIO 3 and GND. You didn't specifically say that you wanted this 1-button arrangement, but it's far more convenient than using separate buttons for shutdown and startup. The only good reason I can think of to do it any other way is to reduce energy consumption while leaving power connected to the RPi.

  • Shutting down your RPi - whether done with a button press, or from the command line - does not remove power. Your RPi will continue to consume some power in shutdown unless and until you "pull the plug".

That said, let's review the options:

Option 1. Move I2C from GPIO 3 and GPIO 4

The latest version of the firmware provides numerous overlay options for "relocating" I2C1, and/or "adding" I2C buses in /boot/config.txt. Review the latest version of the README for details.

This is the easiest option, and you need not read any further unless you need to minimize power consumption while in shutdown.

Option 2.

The RPi 4 introduced a new bootloader that's stored in EEPROM (instead of a bootcode.bin file). It also provided new configuration properties - two of which are relevant to reducing power consumption while the RPi 4 is shutdown or halted; i.e. the system is not running, but is powered up:

WAKE_ON_GPIO

If 1 then 'sudo halt' will run in a lower power mode until either GPIO3 or GLOBAL_EN are shorted to ground.

Default: 1 (0 in original version of bootloader 2019-05-10) Version: All

POWER_OFF_ON_HALT

If 1 and WAKE_ON_GPIO=0 then switch off all PMIC outputs in halt. This is lowest possible power state for halt but may cause problems with some HATs because 5V will still be on. GLOBAL_EN must be shorted to ground to boot.

Default: 0 Version: 2019-07-15

This informs us that the GLOBAL_EN input node may be used in lieu of GPIO 3 to restart the RPi 4 in all possible configurations of these parameters. Three things should be noted re GLOBAL_EN:

  • It is not a GPIO
  • It is pulled up to 5V
  • The actual restart is not* triggered when GLOBAL_EN is pulled LOW by pressing the pushbutton, but when it is "released" and allowed to return to its "pulled-up" (logic HIGH) state.

The GLOBAL_EN node is shown in the photo below:

GLOBAL_EN node location on RPi 4

Summary for Option 2:

This is more difficult than Option 1, but offers the advantage of reduced power consumption in halt/shutdown. The most straightforward hardware implementation is to use two pushbuttons - one for startup, one for shutdown. If you want to take some additional effort, a single button startup & shutdown solution is illustrated here.

Seamus
  • 18,728
  • 2
  • 27
  • 57