Raspberry Pi RetroPie Shutdown Button

Sdílet
Vložit
  • čas přidán 23. 07. 2024
  • Shutting down RetroPie usually requires the use of a menu in the Emulation Station interface. This tutorial explains how you can do this via a shutdown button connected to the Raspberry Pi’s GPIO header. All you need is a basic momentary action switch, some wiring and a simple Python script. It’s probably the most useful upgrade you can make to a Raspberry Pi based gaming system.
    It's not mentioned in the video but you can also get to the command line by connecting a keyboard and pressing F4. You can return to the EmulationStation interface by running the command "emulationstation".
    Reference information
    ---------------------------------------------------
    Install GpioZero:
    sudo apt-get -y install python3-gpiozero
    Script Download URL:
    bitbucket.org/MattHawkinsUK/r...
    Crontab entry:
    @reboot python3 /home/pi/retropie_shutdown.py &
    Shutdown Switch Blog Post:
    www.raspberrypi-spy.co.uk/201...
    Enable SSH in RetroPie Blog Post:
    www.raspberrypi-spy.co.uk/201...
    Putty SSH Client:
    www.putty.org/
    Follow me on your favourite social media platforms:
    ---------------------------------------------------
    Twitter
    / rpispy
    Instagram
    / rpispy
    Pinterest
    / rpispy
    Facebook
    / rpispy
    MeWe
    mewe.com/join/raspberrypiforever
    Google+
    plus.google.com/+RaspberryPi-...
    CZcams
    / rpispy
    Tumblr
    www.tumblr.com/blog/rpispy/
    or visit my website :
    www.raspberrypi-spy.co.uk/
    ---------------------------------------------------
  • Věda a technologie

Komentáře • 51

  • @johnjames01
    @johnjames01 Před 5 lety +3

    This is great. I ordered my Pi 3b+ today and I intend to put Retropie on it. I'm a novice at this but willing to give it a go. Excited to get going with it 😊

  • @sethproaps8899
    @sethproaps8899 Před 5 lety +2

    I love that you added how to chenge the shutdown pin, because in my case I have a PiMoroni battery supply, that takes up pins.

  • @BSAElectronics2014
    @BSAElectronics2014 Před 5 lety +1

    Very good walk thru and thanks for making your script public. Subscribed!

  • @maverickgoose2956
    @maverickgoose2956 Před 5 lety +3

    Thank you! Worked first time. No haste what so ever. 10/10.

  • @Hiroak
    @Hiroak Před 5 lety

    This was perfect, very easy to follow even for someone like me with zero experience working with "coding" if this is coding I don't even really know. It works perfect for my retropie gaming setup.

  • @obtainiumgaming4472
    @obtainiumgaming4472 Před 4 lety +1

    Thank you sir. Short and to the point. I like.

  • @fabioferrara1574
    @fabioferrara1574 Před 4 lety +3

    Thank you so muck, all is perfect!

  • @rbndmx
    @rbndmx Před 4 lety

    Thank you so much for share, this is exactly what I needed, i'm very happy =)

  • @jymferrier
    @jymferrier Před 4 lety

    this was perfect. Thank you!

  • @TheREALBadpun
    @TheREALBadpun Před rokem

    thank you so much for this, it still works and it just saved my ass thank you!

  • @meande-man5351
    @meande-man5351 Před 5 lety

    Works a treat!

  • @defiant3636
    @defiant3636 Před 4 lety +1

    Nice video man. Super simple for a noob for me and works like a dream. Works great only question, is there a way to update so it turns the system on two? Please could you do a video on that ?

  • @KAKAROTOCES1981
    @KAKAROTOCES1981 Před 5 lety +3

    Hi, there is a way to use this button to power on / turn off with the same gpo pins???.

  • @WellBeSerious12
    @WellBeSerious12 Před 5 lety

    How to change script for pin headers 5 and 6?

  • @vikvanderhaeghen200
    @vikvanderhaeghen200 Před 5 lety

    Thank you!

  • @horizon42q
    @horizon42q Před 3 lety +1

    Good video

  • @jamesferguson9354
    @jamesferguson9354 Před 6 lety +6

    Is there a way to power the raspberry pi on with this button

  • @theAristocrap
    @theAristocrap Před rokem

    What if I have another board (audio card) over pi and I don't have open slots. Can I solder directly over card? (X400)

  • @mattivirta
    @mattivirta Před 2 lety

    i do my raspi4 8gb bullseye all this manual scripts and somethink but not shutdown if bush button newer. somethink this video have lot wrong. crontab have make and can see this all py scripts have /home/pi folders. and has sudo reboot after all has make. but button no working i change only code my button have installer gpio 21 and gnd.

  • @Resimaster
    @Resimaster Před 5 lety

    Great video! Thanks for posting. Is there a way to get a script to run other commands with an external button press, for example "insert coin"?

  • @mvl8209
    @mvl8209 Před 3 lety

    Will this work with the Pi 4B (aka the exact way like int this video)? Or do I simply have to look up the pin layout of the GPIO on my Pi 4B that runs Raspberry Pi OS Lite?

    • @RPiSpy
      @RPiSpy  Před 3 lety

      This should work on the Pi 4 as the 40-pin GPIO header is the same as it is on the previous Pi models.

  • @PeterRome
    @PeterRome Před 6 lety

    Great tutorial covering exactly what I needed. Do you know by any chance how to add an LED that would be powered when the PI is on? Thanks a lot.

    • @RPiSpy
      @RPiSpy  Před 6 lety +1

      There are a few options for the LED. You could put an LED in series with a resistor across either 5V or 3.3V and ground. That would illuminate while the Pi has power. The other option is put the LED on a GPIO Pin, turn that Pin High on startup and then turn it off once the shutdown script has been activated.

    • @PeterRome
      @PeterRome Před 6 lety

      Thanks a lot. How would you define the resistor for the LED?

    • @RPiSpy
      @RPiSpy  Před 6 lety

      If you are using a standard LED that will have a forward voltage of ~2V. So using 5V will drop 3V over the resister. A current of 5mA will be OK and using this calculator : www.raspberrypi-spy.co.uk/tools/simple-ohms-law-calculator/ gives a resistance of ~600ohms. If you play with current values of 3mA-10mA gives you a range of 300-1000ohms. I have lots of 330ohm resistors so I tend to use those.

  • @StanMoi
    @StanMoi Před 5 lety

    Thanks!!!!!

  • @khanali5390
    @khanali5390 Před 6 měsíci

    Will this work on any OS ? (New to pi)

  • @TheNikolaschoulakis
    @TheNikolaschoulakis Před 6 lety +2

    How did you get power for the led in your switch ? Did you connect it to the +5v gpio?

    • @RPiSpy
      @RPiSpy  Před 6 lety +1

      The illuminated switch had two LED contacts and was designed for 12V. I just connected them to Pins 4 (5V) and Pin 6 (Ground). It has no effect on the switch functionality but looks a bit nicer. There are more details on that style of switch on my blog post : www.raspberrypi-spy.co.uk/2018/03/raspberry-pi-retropie-shutdown-button/

  • @aboimpinto
    @aboimpinto Před 6 lety +1

    Would be nice to have a button that turn the RP3 on and off like this

    • @RPiSpy
      @RPiSpy  Před 6 lety

      To add a button to completely turn off the power you would need additional hardware. The hardware would need to cut off the power after the Pi was shutdown but without cutting it off too soon. For me this was a good enough compromise. If the mains isn't switched off at the wall it doesn't really matter as the power consumption is so low at that point. But, yes, a proper universal power switch would be nice :)

  • @louf7178
    @louf7178 Před 3 lety

    For a blind shutdown [no monitor]:
    [may need to press MENU to wake wireless controller]
    (MENU (Start) [wake from screen saver])
    MENU (Start)
    RIGHT SHOULDER (6 clicks down), A
    RIGHT SHOULDER (3 clicks down), A, A
    Unplug (power off) unit
    Shorthand [with wakened controller]:
    (M), M, R.S., A, R.S., A, A

  • @troymcdonald
    @troymcdonald Před 2 lety

    Thanks for this. Is this the same for RPi4? And, have you figured a way to shut down the pi and then machine (lights/monitor) after the pi shuts down? (A one button solution)
    Thanks

  • @jnkmal9519
    @jnkmal9519 Před 5 lety +3

    @5:51 Your outlets have power switches?! Sliiiiiick

    • @RPiSpy
      @RPiSpy  Před 5 lety

      LOL. Yeah we're truly living in the future :)

    • @DigitalGus75
      @DigitalGus75 Před 5 lety +1

      Australia too... all our outlets are switched.

  • @ricardovargasopitz4549
    @ricardovargasopitz4549 Před 5 lety +1

    I was searching for a way to power it up :( , to shut down i can do it from the menu.

  • @fen411
    @fen411 Před 6 lety

    Did anyone manage to use this single switch to turn the machine back on again? In other words, if you press and hold the button it turns off and if you press and hold the same button again it turns back on?

    • @RPiSpy
      @RPiSpy  Před 6 lety +1

      It's not possible to use the same switch as once the Pi has shutdown there is no system running to monitor the GPIO pins. You could fit a momentary switch to the 2-pin "RUN" header which will re-boot the Pi assuming the power is still applied to the microUSB port.

    • @fen411
      @fen411 Před 6 lety

      Thanks for the quick response. I'm a NOOB so be kind. I found this bit of script:
      #!/usr/bin/python
      oldButtonState1 = True
      while True:
      # Check the current button state
      buttonState1 = GPIO.input (22)
      # Check for button push
      if buttonState1 != oldbuttonState1 and buttonState1 == False:
      subprocess.call ("shutdown -h", shell=True,
      stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      oldButtonState1 = buttonState1
      time.sleep (.1)
      Although promising I couldn't get it to work :(
      But not knowing python at all I don't know why, I was wondering if it was possible to combine the two??

    • @HoolyHoo1
      @HoolyHoo1 Před 6 lety +4

      Raspberry Pi Spy Yes it is possible. You simply need to use gpio 3 (physical pin 5) instead in the script. That pin will reboot the pi similar to the run header when grounded but can still be used as the shutdown gpio in the script. As long as the microusb is powered it will work as a dual on/off switch.

    • @fen411
      @fen411 Před 6 lety

      Awesome cheers

    • @msyahabudinishak6920
      @msyahabudinishak6920 Před 5 lety

      HoolyHoo1 cool... can this switch use to reboot while in the main menu? instead of going to restart emulationstation...

  • @mikem8145
    @mikem8145 Před 6 lety +1

    GPIO 15 or 22 ? I'm confused

    • @RPiSpy
      @RPiSpy  Před 6 lety

      Pin 15 on the 40-pin header is GPIO22.

  • @christophermugford4555

    Do you know how to uninstall? Thanks!

    • @RPiSpy
      @RPiSpy  Před 5 lety +1

      Uninstall GPIOZero?
      sudo apt-get --purge remove python3-gpiozero
      but you would also need to delete the entry from the crontab to stop it trying to run the script on boot.

  • @willmoindrot
    @willmoindrot Před 3 lety

    Thanks for this useful video, it helped me get started. However I found on my install (RPi4 Retropie) adding as cron (following your instructions) did not get it working. It would run if I started your python from the command line but on reboot nothing happened. I tried logging but that didn't report anything, I also tried putting in a sleep duration, still no dice. Instead I added as a command in rc.local and that got it working on a reboot (no idea if that approach is now depracated): www.raspberrypi.org/documentation/linux/usage/rc-local.md