This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GPIO power button for Raspberry Pi
#8
(2022-01-01, 08:59 PM)aardvarkash10 Wrote:
(2022-01-01, 04:20 PM)abarrow Wrote: The only thing I can think of is an external circuit that has something like a 20 second timer that starts when the RPI gets the shutdown command. This would give it time to shut down before the timer expires and disconnects the power completely.

Thanks for the reply.  

The time to power down thing is not a big issue - I can resolve that with a simple capacitor/resistor network that stores, say, 20s of power at the output of the UPS. eg 12v>UPS>Power Switch>Storage Network>12v:5vstep-down>RPi

Its the software that is my downfall!

you may need to do some googling to get this right and may have to look at which GPIO pins are naturally pulled up and down.

Below are my instructions to add the momentary switch, which just involve some minor changes to config.txt:

Momentary Shutdown switch
Connect up the momentary switch across Pin 39 and 40, if the led has a separate ground then connect up the LED using 38 and 34. Watch polarity.
 
In the file /boot/config.txt (use sudo nano /boot/config.txt)
 
Add the following:

Code:
#on/off switch
dtoverlay=gpio-shutdown,gpio_pin=21
dtoverlay=gpio-poweroff,gpiopin=20,active_low="y"

GPIO numbers are different than the pin number so make sure you use GPIO20(actual pin 38) and GPIO21 (actual pin 40)
 
The behavior you will see is that when Pi is booted up the LED will come on.  When the momentary switch is pressed, the PI will shutdown and once safely down, the LED will power off.  the main power can be turned off safely now.

what I think you need is the opposite to the statement above where the power (for the led) would be low, then go high at 'poweroff'.

I have since changed this circuit and added a relay to disconnect my permanent power source (in this case your ups).  the code I use is below:


Code:
dtoverlay=gpio-shutdown,gpio_pin=21,gpio_pull="down",active_low=1
gpio=20=op,dh

the system is connected to the instrument breaker and a permanent 12V, through a relay.  the system boots when the instrument breaker is turned on and powers down when the instrument breaker is turned off.  On power down, pin 20 is depowered and disconnects the permanent 12V supply totally isolating the Pi.

hope this helps
Reply


Messages In This Thread
GPIO power button for Raspberry Pi - by jlazkano - 2021-12-26, 10:00 PM
RE: GPIO power button for Raspberry Pi - by Techstyle - 2022-01-01, 10:28 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)