Posted on

RetroPie Shutdown and Startup Switch – The Easy Way

Tired of unplugging your Raspberry Pi to turn it off?

Don’t want to purchase one of those switched USB power adapters and have to shutdown your Pi from a menu every time? Do you also want an easy way to turn your Pi on?  There’s a script for that.  And you may have already seen it floating around on YouTube but there’s a lot of code you have to copy and paste to get it working.  So, want a push button that can turn on and safely shutdown your Pi, and an easy way to get the software working?  Well, here it is –

Hardware setup:

You will need to connect a momentary switch from pin 5 (GPIO 3) to pin 6 (GND).  Pin 6 tends to be the most convenient ground, but it doesn’t actually matter which one you use – pins 6, 9, 14, 20, or 25 will all work.  See the pinout if you’d like to use a different ground pin.

Raspberry Pi Pinout (all versions)

Pi 3 Connections:

Raspberry Pi 3 Reset Pins

Pi Zero Connections:

Raspberry Pi Zero Reset Pins

You can use pretty much any momentary switch that is normally open.  You can even use a reed switch for a magnet activated switch to avoid drilling holes in your case!

On Raspberry Pi 3, you will need to connect pin connectors (Dupont connectors) to the switch wires, or find a switch that already has them (just an example, not a recommendation).

If you need to add pin connectors to your switch, you can solder/splice on female Dupont wires.

Or, (especially if you plan to do multiples), you can crimp your own connectors with a kit like this.  While, it is *possible* to crimp those connectors with some regular pliers, it’s not really ideal so you’d also want to get a crimping tool.

Software setup:

Once you have your switch connected, you will need to install a bit of software to allow the switch to shut down your Pi (pressing the switch while the Pi is shut down will turn it back on without any software.) Your Pi needs to be connected to the internet to download the install script and packages.

Hat tips to Barry Hubbard who I believe is the originator of the Python script that makes this work, and to ETA Prime for creating an awesome how-to video that’s popularized this mod.  I used ETA Prime’s video to do this initially and realized that the process was more complicated and error prone than it needs to be.  So, I created a script that automates the entire software setup.

There are two ways you can run the setup script: using a keyboard plugged into your Pi, or over a network terminal session using your computer. Using your computer over the network was the preferred way to do this using the ETA Prime instructions due to the amount of copying and pasting required.  However, it’s might be easier to use a keyboard (at least in the UK) for this method unless you’re already set up to connect over the network.

Keyboard Method (UK):

  1. Press the start button on your game controller and exit emulationstation to get to the shell.
  2. Type the following and press enter:

curl | bash

That’s it! You’re done.

(Skip to testing section)

Keyboard Method (US):

Some distros including RetroPie have the keyboard layout set to GB by default, so there’s no way to type the | symbol on a US keyboard. So you can do this instead:

  1. Press the start button on your game controller and exit emulationstation to get to the shell.
  2. Enter the following commands (press enter after typing each line)

curl --output

sudo chmod +x


That’s it! You’re done.

(Skip to testing section)

SSH/Network Method:

Make sure your Pi is connected to the same network as your computer either via Wifi or Ethernet. For Pi Zero you will need a WiFi dongle.

Using Windows:

  1. Download putty.exe to your desktop (if you have a relatively modern computer, you probably want the 64-bit version)
  2. Start putty
  3. Enter ‘retropie’ as the host name, make sure SSH is checked, and click open.
  4. If you are presented with a security alert about the server’s host key, click yes.

Using Mac/Linux:

  1. Open the Terminal application.
  2. Type ‘ssh retropie’ and press enter.

Host not found / other error?

If you get an error like ‘host not found’, you may need to use the IP address vs the host name of the Pi.  To get the IP address: in RetroPi select the RetroPi channel and select Show IP.  Use the IP in place of ‘retropie’ in the previous instructions.

Once you’ve connected:

  1. Once you’ve connected to the Pi via SSH, you will be prompted for a username and password. The username is ‘pi’ and the password is ‘raspberry’ (all lower-case).
  2. You should now be at a shell prompt. Copy and paste the following command and press enter:

curl | bash

That’s it! You’re done.


Now the shutdown script should be installed and set up to run every time the Pi boots.  To test it out, press the switch.  The Pi should shut down.  Press the switch again and the Pi should boot up.


If your Pi didn’t shut down, shut it down manually.  Press the switch.  If your Pi doesn’t start up, there’s something wrong with your switch/wiring/connection.  If it does start up, wait for emulationstation to load and press it again.  If it doesn’t shut down, there’s something wrong with the software setup.  A good place to get help at that point would be the RetroPie gaming group on Facebook.


Copyright © 2017

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

140 thoughts on “RetroPie Shutdown and Startup Switch – The Easy Way

  1. Will this work if there is a rtc installed as well? The rtc board uses pins 1,3,5,7,9

    1. Probably not. PIN 5 is special in that it can wake the Pi up from deep sleep (“off”) so if your RTC board requires it, I don’t think the shutdown script will work.

  2. Will this work with an on/off switch not momentary?

    1. no, it needs to be momentary

    2. Yes, you can make it work with a permanent switch – you’ll need to edit the shutdown script to:
      a. Invert the value of the ‘old’ variable at script start
      b. Remove the second check on the main If there

      I’ve written these very vaguely because I don’t have the script on this PC, I’m just going from (bad) memory. But it’s a pretty simple script, you should be able to figure it out from these vague instructions once you see it.

      1. Could you please elaborate a bit more?

  3. Can I use these with another OS like raspbian? Btw nice work!

    1. I think so

  4. That´s great, would this work on Recalbox too?

    1. I think so

      1. I want to turn a out put on when it powers up, (connected to relay, which controls an ATX power supply) and turn pin off when powered down, I have written the to pyton programs, but how do I incorporate into your script to make one run on power up, the other on power down?

        basically when pi is on want a 3.3v pin going high, when asleep a 3.3v pin going low.

  5. Where can I setup a hold time to signal power down?

    IE: PiCade Hat has a 3 sec hold time for shutdown while a momentary press to start up.

  6. I was able to modify this script to use a 3 sec hold to shutdown. here is the full moded script

    import RPi.GPIO as GPIO
    import time
    import subprocess
    from threading import Timer


    SHUTDOWN_HOLD_TIME = 3 # Time in seconds that power button must be held

    # we will use the pin numbering to match the pins on the Pi, instead of the
    # GPIO pin outs (makes it easier to keep track of things)
    # use the same pin that is used for the reset button (one button to rule them all!)
    GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)

    def perform_shutdown():“shutdown -h now”, shell=True,
    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    oldButtonState1 = buttonState1

    oldButtonState1 = True

    while True:
    #grab the current button state
    buttonState1 = GPIO.input(5)
    global shutdown_timer
    # check to see if button has been pushed
    if buttonState1 != oldButtonState1 and buttonState1 == False:
    # shutdown
    shutdown_timer = Timer(SHUTDOWN_HOLD_TIME, perform_shutdown)


    1. awesome, thanks!

    2. Question to Dan
      Is it something more to do except writing the script.
      I can’t get it to work the button is not responding.
      it worked before but not with the timer.

      Is it something to do with “from threading import Timer”.

      1. I am also curious about this issue as I also cannot get the code to work. Any insight or solutions would be greatly appreciated.

    3. Hi, I tried substituting your code for the code in the script but I cannot seem to get it to work.

      Is the way it is depicted in your text box the way I can cut-paste it into the script or are there changes I need to make to it on account of textwrapping in the comment box causing the code to appear other than how it is supposed to look in the editor. Thanks in advance!

    4. can you email this to me in a text file w/ the indenting intact?

      1. can you send me that email as well? Thanks in advance!

      2. Were you able to get the required information to modify your original script to the one with the delay?

        1. try this:

          Let me know if it works; I haven’t had a chance to test it yet.

          // edit: may 5 2019, I changed the link to point at a version where the quotes issue has been fixed.

          1. The problem is the quotes surrounding the “shutdown” command in the last line of the code.
            They are being replaced with alternate characters, so they are not recognized by the interpreter, and that is why we get the error:
            SyntaxError: Non-ASCII character ‘\xe2’ in file /home/pi/scripts/ on line 26, but no encoding declared; see for details

          2. Thanks Luis, I’ve fixed the original post

  7. Unfortunately this does not work so well with the official pi 7″ monitor with touch enabled, since the monitor also uses those two pins for the touch interface.

    1. yeah, anything that uses pin 5(the official touch screen and several hifi berry sound cards) require a 2 button approach. just get the shutdown code and change pin 5 to the pin of your choice and connect one button to your new pin and ground. this button shuts down. connect another button to the “run” header on the pi and that will be “reset” or “power on” that button does not require a script.

      1. sounds like a great solution. thanks for posting

      2. Hi thanks for your idea that seems what I want to do. But I don’t see exactly what you mean by changing pin. Is it possible to have a little draw to show us? Thanks in advance.

  8. I’d love to use this on my pi 3 running Libreelec but I can’t install the script automatically due to the sudo command not being used by default. Any ideas on how to overcome this? Great work!!!

    1. Try removing all the references to sudo or install and setup sudo

  9. I tried it with a recalbox, while install the script it says:

    Updating packages
    bash: line 36: sudo: command not found
    Installing python.gpio
    bash: line 40: sudo: command not found
    Downloading shutdown scripts
    bash: line 46: /home/pi/scripts/ No such file or directory
    ######################################################################## 100.0%
    bash: line 48: sudo: command not found
    chmod: /etc/init.d/pi_shutdown: No such file or directory
    Add pi_shutdown to rc.d
    bash: line 53: sudo: command not found
    Running shutdown listener
    Shutdown is now installed

    Nothing happend when i push the button any suggestions?

    1. Try editing the script to delete all of the `sudo` commands and then run it. Or, install and setup sudo.

  10. im having an issue where a momentary (tried several) hooked up to the pins will turn off the pi but only when pressed twice, shutting down works normal, but then at random intervals when the pi is “off” (sleeping) it turns on by itself… still puzzled…

    1. using “borkin” buttons? very high % of those are defective and need a resistor added to make them work properly

  11. Hey just wanted to say, this is awesome! Worked like a charm. Glad my frantic google searching paid off 🙂

  12. Is there a trick to using the button ?
    Picked one up following the eta prime video
    Soldered up correctly
    Ran the script the link here
    Downloaded the script fine rebooted

    It works sometimes I can’t tell if I need to hold it or just press it sometimes I press it once quick it does nothing other times it works but usually after a couple of minutes of trying

    Any thoughts?

    1. I’ve heard that those buttons are often defective or unreliable. You might check that it’s operating correctly with a multimeter or try a different one. You should have to hold the button down no more than 0.5 seconds or so for it to register.

  13. I’m running the latest version of retropie and attract mode off of a hard drive with a small SD card for booting do I need to do anything fancy to the commands to shutdown the hard drive when shutting the system down with the button ( I’m super new at this) thanks in advance

    1. I don’t think so, but you may want to ask here:

  14. this works great! but my fan stays running after i shutdown… anyway to get the fan to turn off as well?

    1. I can’t remember off the top of my head. You may need to control the fan with a transistor. ask here:

  15. My pi wont stat at all after installing the script. i can see power light on the pi but it just wont do anything, no picture or sound, just nothing.

    1. can you check that your sd card is working (check on your computer) and inserted properly?

      what distro? retropie? what version?

  16. When I plug in a keyboard and type the commands, it doesn’t recognize the url. Am I supposed to be connected to internet, even for the keyboard method? I have a Pi Zero without wifi. If you need to be on wifi, why isn’t that in the instructions?

    1. Yes, how can you get to a URL without being connected to the internet? It wasn’t in the instructions because I must have thought that was obvious, but I’ve edited the instructions to make it more clear. Besides the initial download of the install script, there are several packages that must be downloaded and installed. I don’t know how this can be done offline but I’m sure there’s some linux wizardy that could make it possible. I used a $10 wifi usb dongle to do this on my non-wifi pi zeros

      1. OK, once I figure out how to go online, I’ll try again. For the keyboard method, once I type the script, does it automatically go online and download what it needs? Sorry, I’m a complete idiot when it comes to this. Never used linux before I got the pi a few days ago.

        1. yes, type the script, it does everything else

  17. I’m on NOOBS Jessie, not retropie. Will the script work, and can’t I just short the two pins manually with a screwdriver or similar (0.5s contact), instead of “installing” a commercial switch?

    1. I don’t know about NOOBS. yes you can short the pins w/ anything

  18. What is the startup state when you plug in the usb power?.. I’m interested in making this project, but if the startup state from plugging in is ‘switching on’ without pressing the button it is kinda useless for me. I frequently unpower my pi.

    1. The initial power state is on. I’m not sure if that behavior can be changed; I’m guessing no.

      Why do you frequently unpower and repower your pi?

      1. Hi 8bit, I have all my multimedia hardware set up on a powerswitch, so my speakers and stuff don’t use all the power all the time. Cost and wear effective and all… I don’t always use the pi for watching TV. Sometimes I use a ChromeCast and there is no reason for the pi to be on. If the startup state would’ve been off then I could use it as a separate power switch. I could however use it as an off switch.

        1. +1. Would be best for me too if had to press to switch on after say a power loss. Don’t want it switching on unless I press button.

          1. first wold problems

  19. The script wont install for me. I receive an error that the certificate from the host is not recognized? Nothing installs and there is just a line of zeros above the error? Any help?

    1. I’m not sure why, seems to be working ok for me.

      try removing the ‘s’ from the ‘https’ in the url for the initial command you type in

  20. Raspbian, but not Retropie

    It only works if the HDMI is plugged in.
    If i try power up without HDMI it tries to boot but shuts down within ten seconds.

    1. If i try power up without HDMI it tries to boot but shuts down within ten seconds.

      That’s odd. Are you using a “borkin” button? What kind of button are you using?

    2. I use the 7″ display and I get the same issue, it powers up and 10 seconds later it turns down, I have other 2 raspberries where it is working without issues. Have you found out a way to fix this?

  21. This is great, thank you so much for sharing this, it works great with my NES clone mod that I did…

    shared a link to this awesome guide in my video, thanks again!

    1. awesome, thanks

  22. Finally! Other methods I tried either simply did not work or caused RetroPie to not boot properly.

  23. Im having problems trying this two different ways. I installed the wire and borkin button with no problems. Followed ETAPrimes video.
    1st version problem using putty – When I use Putty I enter the ID and PW correctly then the green indicator in the command window moves down one line and nothing happens.
    2nd version problem using keyboard – I enter the first line and hit enter. I enter the second line (sudo chmod +x and it says “chmod: cannot access no such file or directory”

    1. sounds like your pi isn’t connected to the internet?

  24. Worked as described.

    My setup is a straightforward Retropie installation (C64 Breadbin mod) with no GPIO connections so pins 5+6 are available and work as above.

    Used the putty ssh and script set up with no issues.

    Button both shuts down and starts up the Pi

    I generally shut the system down via software but this will be a good manual shutdown if the system hangs up

  25. The script worked flawlessly on my Raspbian Jessie. Just now i formatted the microSD card and installed Raspbian Stretch from scratch, followed by sudo update&upgrade. Rebooted. And then installed the script. The script does not seem to work any longer, since i am on Raspbian Stretch. Please could you check?

    1. After a reboot, the script doesn’t seem to be active. So when i enter “sudo python /home/pi/scripts/”, i get the output “/home/pi/scripts/ RuntimeWarning: A physical pull up resistor is fitted on this channel! GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)”. Maybe this helps for trouble shooting?

    2. I updated the scripts. Try running it again; should work now.

  26. It only works after installation. After first reboot, doesn’t work anymore.
    I am using Raspbian Stretch on Pi 3.

    1. I updated the scripts. Try running it again; should work now.

      1. i’ve reinstalled the (new) script. no change. only works after installation (1st shutdown, and then 1st reboot). after the 1st reboot a 2nd shutdown doesn’t work.

        1. hm..

          what happens if you “sudo python /home/pi/scripts/” ?

          please post the results of “cat /home/pi/scripts/”

        2. I don’t get notified if you post here. You can email me for faster response: 8bitjunkie8
          at gmail

  27. I’m currently building a setup that will be using two original SNES controllers via the GPIO using the gamecon_gpio driver and it uses pin 5 and 7 for the controllers. what and where would i have to change your script to use, say Pin 40 (GPIO21) and 39 (GND)? Sorry, I’m pretty new to using the GPIO pins for anything on a Pi.

  28. I agree with the last comment, the script will run for the Power On but will not Power Off after the first cycle. To be fair its good enough for me but I think it would be nice to have it powering on. If you run:
    sudo python /home/pi/scripts/
    …whilst in SSH then the Pi3 will Power Down as scripted.

    1. I’m a H/W guy and have read this whole thread. A friend and I are working with a Pi3 with HiFiBerry HAT. My first question is why was GPIO3 (pin 5) chosen to be “special” as in toggling that pin while the Pi is asleep wakes it up? GPIO3 is the SPI bus Clock signal used along with GPIO2 (pin3) SPI bus Data to query a HAT’s EPROM for its identity so those two are automatically “stay-away” pins when a HAT goes on. Seems like an odd choice. Is that GPIO3 wake-up function cast in stone? Second question is that I see Off/On gizmos for sale at Mausberry that require a (HAT-less) connection GPIO23-24 (pins 16 and 18) and apparently the gizmo comes with a script. Button presses not only initiate a soft shut-down but also wake the Pi up. How does that work? Who’s watching those pins while the Pi is sleeping? Or am I missing something? Thanks for any education at all.

      1. pin 5 was chosen by the raspberry pi firmware developers. if you google hard enough you can find a little bit of info about it including in some developer forums where they talk about it- it was a feature they added later on in the cycle. Sorry, I don’t have any links handy.

        the research I did do seems to indicate it would be possible to modify the firmware to change that pin but that may be pretty complex to do. and, I haven’t been able to find specific enough information on where that code is or how you’d go about picking a different pin, or how the firmware flashing would actually be done.

        the mausberry is basically a relay in front of the power to the rpi. to turn it on, if I recall correctly, it simply allows power to flow to the turned-off pi which causes it to boot. there is info on the mechanics behind the mausberry online (maybe including code/design files, can’t remember).

        if you have more questions, I’d suggest asking them in this facebook group:

  29. Dan’s script will not work without proper indentation. I’ll indent it and report back

  30. After installing this script, the button functions, but I after the Retropie splash screen, I get what seems to be a debug screen with an error:
    “home/pi/scripts/ RuntimeWarning: A physical pull up resistor is fitted on this channel!
    GPIO.setup(5, GPIO.IN)”

    It was suggested I add GPIO.setwarnings(False) to the script before it starts defining the pins to ignore the warning, but that has not affected it in any way. I’m in way over my head when it comes to scripting, so I have no idea where to go for troubleshooting that.

    1. sorry, I’m not sure. A few people were having this problem when retropie moved up to a newer version of raspian. at that time I modified the script to fix that, but it seems some people are still running into it.

      are you using the regular script or the version for the nes pi case? what version of retropie?

      you might try asking in They are better at keeping up with things than I am currently.

  31. I’m running lebreelec on pi3. The wake function is working but not the shutdown. Is there as easy way to uninstall/delete the script to start over?

    1. you can try:

      sudo update-rc.d -f pi_shutdown remove

      let me know how that works

  32. This aparently bombed my systemfile, cant get back into emulationstation after using the script

    1. that’s weird…sorry

  33. Something about the `python-rpi{,3}.gpio` modules appears to conflict with RetroPie’s `snesdev` GPIO driver which I use for a Monster Joysticks kit:

    Once the shutdown script was installed, the joystick stopped registering events in `jstest`. I tried just commenting out the init script for the shutdown daemon which didn’t help, then I uninstalled the Python modules which still didn’t help, and then I reinstalled the `snesdev` driver and the stick started polling events again. Maybe I can install the Python modules and then reinstall the `snesdev` driver to overwrite whatever stomped on the driver, I don’t know. Just curious if anyone else has run into this?

    1. you can try:

      sudo update-rc.d -f pi_shutdown remove

      to uninstall the switch script. let me know how that works

  34. Im curious..I have a HAT sound-card on top of the PI3. The sound-card supplies power to the Pi. I could add the button to the sound-card except I need the headphone jack for my headphones. Is there another way I can install this button and get the Borkin button to turn off the PI?

  35. A question.
    Is this script looping every 0.5 seconds to check if the pins are bridged in order to perform the safe shutdown?

  36. Having the same problems mentioned above.. only working to startup not working to shutdown.. any solutions yet on how to get it working?

  37. I have built a couple of Retropie systems in the past, and this setup script has worked first time.

    Just this week, I built a new system based on Raspbian Wheezy. When I installed the script, everything appeared to work as it should without any error messages, but when the system is rebooted, the is not run which means the shutdown function of the switch won’t work. In the end, I managed to get it working on boot-up by adding the following to the file /etc/rc.local:
    sudo python /home/pi/scripts/ &> /dev/null &

    Does anyone know which startup or rc file is responsible for running the file /etc/init.d/pi_shutdown?

  38. As far as I can tell, something in Raspbian Strech prevents the script from being run at boot time. As a work-around, you can try adding it to rc.local with ‘sudo nano /etc/rc.local’, then add the following line above where it reads exit 0:
    sudo python /home/pi/scripts/ &> /dev/null &

    Using putty will allow you to copy and paste the line, thus avoiding typos.

    Reboot the Pi and run ps -aux|grep shutdown to confirm whether or not the script is being run.

    1. This workaround worked for me on my Pi 3 B+ running Raspbian Stretch.

      Thanks heaps.

    2. @ElShiftos my man!!!! you are a god among men, thank you for this solution.

  39. So, here’s my problem. I have a NesPi case and did the ETA Prime mod. It gets up to the RetroPie splash screen, then shuts down. I tested the power and on the pin 5, it measures 0.0v until I press the reset button, then it goes up to 3.3v. I’m assuming that’s what it’s supposed to do.

    But, after I run the script, it shuts down the pi, and nothing else happens. I took the pi out of the case, and it does the exact same thing. I tried holding the reset button down while it was booting, but it does the same thing also. I even tried removing the wire to pin 5, no dice there either.

  40. Not working on Retropie 4.4 (Stretch)

  41. This doesnt work with the raspberry pi 3 b+ unless im doing something wrong ive had no luck

  42. since he wont respond to anyone. the script will no longer work with 4.4. to get it to work:
    edit rc.local:
    sudo nano /etc/rc.local
    add this before the end of the file:
    python /home/pi/scripts/ &

    hope this helps everybody

    1. Thanks! This worked or my on Raspbian.

  43. Thanks heaps! Works perfectly with RetroPie v4.4, then SSH via Putty on Windows 10.
    Connect momentary “mini spring button” switch to pins 5&6.
    Copy/Paste: curl | bash
    Reboot and worked like a charm for me 😉 Cheers 8bit!

    1. Sorry correction, my version of RetroPie is actually v4.3.5. but still very happy this works – looks like I might hold off going to v4.4 for a bit.

  44. Wow. For the first time in my life trying something like this, it worked first time. You sir, are a genius. Thanks for the share.

  45. hey so dose this still work with the 3.5mm headphone jack? if not is there a way to get it to work?

    1. so i get it to work but once i shut down/ start up once i have to reinstall it

      1. if anyone is trying and its not working you can use this, its for a retro pi nes case but it uses the same pin and works after a shutdown and reboot on pi 3b+

  46. Hi, does the script work on a computer with Raspbian (octopi)? I will not want to put a script that disfunctions my Raspberry. (raspberry 3B+) Thanks a lot for your answer.

  47. Is it possible to change the pin by editing the script? Where then is it located…?

  48. Hi, 8bit! I successfully installed the program, it shut down and powered on successfully! But after the first button caused auto startup, the shutdown function no longer works. I did saw the same problem you mentioned in the article, you told us to go to facebook and ask them. I sent the request to them, but I’m not in yet. Do you know how to solve this problem? Thanks!

  49. I tried this on/off button implementation on my two Pi’s and it is working just fine. It was not quite as easy as expected.

    One Pi (and older B+ model) is running DietPi and I did have to tweak the shutdown script as I was getting a “a physical pull up resistor is fitted” error. I had to remove the “pull_up_down = GPIO.PUD_UP” argument from the “one button to rule them all” function call.

    The other Pi (a new 3 B+) is running Raspbian and I had to manually add the line to run the shutdown script to the rc.local file. So, now upon reboot, it will run that script.

    1. Do you mind guiding me step by step after install?

  50. This is marvelous! Thanks for the work, we now have shutdown on our RPi 3B+.

  51. I set everything up, and it worked great… once.. after the first reboot I would have to initiate the script ( again, and it would work 1 time, then nothing.. up todate raspian

  52. If it doesn’t work for you a second time/after a reboot, the solution Justin posted above worked for me and is here for your convenience. Thanks 8bit and Justin!

    the script will no longer work with 4.4. to get it to work:
    edit rc.local:
    sudo nano /etc/rc.local
    add this before the end of the file:
    python /home/pi/scripts/ &

  53. Why wont this work on a Pi running Octoprint?

  54. This is great! Thanks for the guide. I installed it today and came across the same problem as Chris c Krimtisos. The button worked once, then after reboot nothing. Came here, saw last comment has same issue, reading more comments I saw Justin mention that the script no longer works with 4.4 raspbian unless you add it to the rc.local file so it can be started on boot.

    June 19, 2018
    “since he wont respond to anyone. the script will no longer work with 4.4. to get it to work:
    edit rc.local:
    sudo nano /etc/rc.local
    add this before the end of the file:
    python /home/pi/scripts/ &

    hope this helps everybody”

    This makes the button work after reboots.

    Hope this helps some future people getting this button to work, it’s totally worth it! So simple and inexpensive. Oh and if you are scared to solder in case of perma ruin, use a glue gun. I picked one up at the 1$ store and worked like a charm!!

    Thanks again to the people who figured out how to do all this!!

    1. don’t work for me. i had added it in rc.local but the raspberry pi 3b+ doesn’t shutdown but it turn on.

  55. The one issue I do seem to still have is that the button doesn’t work unless the monitor is plugged in. I don’t know if this is normal or not, can the button be used on a headless system? I was putting on my pi-hole that doesn’t have a screen attached.

    The pi seems to boot up, read light flashes, then the nic flashes, then the nic lights shut off and I cannot reach the pi via ssh. If I plug the screen in and press the button the pi boots up as normal.

    Anyone know if it is possible to use this type of button/script with a headless pi?


  56. I figured out how to use with a headless pi, for those wondering you have to have hdmi_force_hotplug=1 set in the /boot/config.txt this sets the pi to use HDMI mode even if no HDMI monitor is detected.

  57. @Randy, Thanks I could not figure out why my pie wouldn’t shutdown. I also had to add the file to the rc.local file. My pie would start up but not shutdown with the button until it was added to the rc.local file. Thanks!

    1. same to me

  58. Thank you !

  59. Using a debian distro (Kali)

    When running
    root@kali:/home/pi/scripts# sudo python ./
    Traceback (most recent call last):
    File “./”, line 2, in
    import RPi.GPIO as GPIO
    File “/usr/lib/python2.7/dist-packages/RPi/GPIO/”, line 23, in
    from RPi._GPIO import *
    RuntimeError: This module can only be run on a Raspberry Pi!

    ? Anyone know how to modify it on a different distro?

  60. Using RetroPie – Stretch

    Even after adding
    python /home/pi/scripts/ &
    exit 0

    Also added
    to config.txt

    It still does not shutdown when pressing button. It boots up from a shutdown (still powered) state so I know that Pin5 is going low when pressed.

  61. When adding this to a command line it seems to register correctly
    python /home/pi/scripts/ &

    Then it shuts down properly.
    Somehow rc.local file is not enabling the python script.

  62. This script is working to shut down and restart, but it is not saving my favorites or last played.

    I just briefly skimmed the other comments and didn’t find my same issue. I’m sorry if I missed it but can someone point me in the right direction?

  63. These pins interfere with Pimoroni Hyperpixel 4″ screens.

    /home/pi/scripts/ RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
    GPIO.setup(5, GPIO.IN)

  64. This script will make your LCD go blank

  65. curl: (6) Could not resolve host:
    curl: (6) Could not resolve host:

    Any idea why I am getting these errors?

    1. Not connected to the internet?

  66. Could not get the shutdown function to work unless I manually ran the code. Found the installer wasn’t adding to an available rc file.
    Did the following as a workaround:

    sudo nano /etc/rc.local
    #Right above exit 0 I added
    /Home/pi/scripts/ &

    Works great now!
    I found the rc.local tip at

    1. thank you!

    2. Hi Carl,
      NOOB here. I added
      /Home/pi/scripts/ &
      in the line just above exit 0. The button still only works for turning on and not for shutdown. What could I be doing wrong?


  67. Hi 8bit,
    I was wondering if this would work on the latest version of libreelec
    And on pi4?


  68. I have the same problem as a few other people in the comments; the button works for turning on but not for shutting down. I did the following as suggested in the comments:

    sudo nano /etc/rc.local
    added the following line
    /Home/pi/scripts/ &
    just above exit 0.

    The button still only works for turning on and not for shutting down.

    Any suggestions to what I could be doing wrong?

Leave a Reply

Your email address will not be published. Required fields are marked *