seamusdemora / PiFormulae

A collection of "How-To" guides or "Recipes" for the Raspberry Pi
64 stars 9 forks source link

Repeat of Issue 4 #7

Closed seamusdemora closed 2 years ago

seamusdemora commented 3 years ago

@fugata commented on Jul 18, 2020 :

Thanks for preparing the tutorial for programming the eeprom to a lower power mode! I am new to pi and I have a question about how this config might affect gpio.

I came upon this mod

https://www.hackster.io/shiva-siddharth/service-to-safe-shutdown-headless-raspberry-pi-boards-708269

that adds an on/off switch for the pi, using the gpio pins to triggle a python script. I wonder if your eeprom change, specifically

set WAKE_ON_GPIO=0 set POWER_OFF_ON_HALT=1

might render the on/off switch mode/script useless?

I have not yet gotten the parts and I am completely new to gpio; your help and comments are most welcome! Thanks!

seamusdemora commented 3 years ago

@fugata asked:

I wonder if your eeprom change, specifically
set WAKE_ON_GPIO=0
set POWER_OFF_ON_HALT=1
might render the on/off switch mode/script useless?

Since posting my original response, I have learned some things that materially affected my first answer. Consequently, I'm re-writing it entirely here:

  1. The modification you linked to misses the significance of the dtoverlay named gpio-shutdown. Specifically, other than adding the one line in /boot/config.txt, no script or additional code is required to implement a "one-button start/stop" (OBSS) solution. There are several items you may wish to read for confirmation or to gain a better understanding of this:

    • The file /boot/overlays/README on your local filesystems, and available online in its most current version. Specifically, refer to the section on the gpio-shutdown overlay.
    • The pull request that led to the addition of the gpio-shutdown overlay.
    • Matthijs Kooijman's blog explaining the genesis and implementation of the gpio-shutdown overlay.
  2. To answer your question about rendering the OBSS useless, I will say that it at least makes it less useful :) Specifically, the button (temporarily shorting GPIO 3 to GND) will safely shut down the RPi, but once it is shut down, another button press will not cause it to startup/re-boot. The issue seems to be that invoking the "Low Power Mode" (LPM) in the bootloader results in removing power (3V3) from all GPIO pins. If you'll refer to the Foundation's bootloader configuration docs, you'll see this definitive statement under the POWER_OFF_ON_HALT parameter:

    GLOBAL_EN must be shorted to ground to boot.

    We also note:

    • GLOBAL_EN is pulled up to 5 volts - not 3.3 volts
    • When the RPi is running, pulling GLOBAL_EN low results in an immediate (and unsafe) shut down.

    And so GLOBAL_EN is not a substitute for GPIO 3.

  3. As I am now working on an off-grid application, I have become much more interested in a push-button to start and stop my RPi. Consequently, I was compelled to find a solution that allowed me to use OBSS and LPM. That led to this hardware-based solution. I have built and tested a prototype, and I can say that "it works". As you'll note from reading issue 6, I continue to look for improvements. For those not interested in this approach, it is of course possible to accomplish startup and shutdown from LPM with two push-buttons: one wired between GPIO 3 and GND, the other between GLOBAL_EN and GND.

    Also worth noting is that the OBSS still works with RPi 4 in the default bootloader configuration. And it seems that RPi 4 now draws less current in halt/shutdown mode; it has been reduced from 370mA last year to 270mA now.