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 😊
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.
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 ?
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.
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/
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 :)
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?
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.
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.
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
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
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?
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.
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??
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.
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.
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
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.
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 😊
Is there a way to power the raspberry pi on with this button
Thank you! Worked first time. No haste what so ever. 10/10.
indeed 👍
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.
Thank you sir. Short and to the point. I like.
Hi, there is a way to use this button to power on / turn off with the same gpo pins???.
Very good walk thru and thanks for making your script public. Subscribed!
What if I have another board (audio card) over pi and I don't have open slots. Can I solder directly over card? (X400)
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 ?
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.
thank you so much for this, it still works and it just saved my ass thank you!
Will this work on any OS ? (New to pi)
Thank you so muck, all is perfect!
How to change script for pin headers 5 and 6?
How did you get power for the led in your switch ? Did you connect it to the +5v gpio?
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/
Would be nice to have a button that turn the RP3 on and off like this
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 :)
Thank you so much for share, this is exactly what I needed, i'm very happy =)
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?
This should work on the Pi 4 as the 40-pin GPIO header is the same as it is on the previous Pi models.
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.
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.
Thanks a lot. How would you define the resistor for the LED?
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.
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
this was perfect. Thank you!
I was searching for a way to power it up :( , to shut down i can do it from the menu.
GPIO 15 or 22 ? I'm confused
Pin 15 on the 40-pin header is GPIO22.
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
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?
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.
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??
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.
Awesome cheers
HoolyHoo1 cool... can this switch use to reboot while in the main menu? instead of going to restart emulationstation...
Do you know how to uninstall? Thanks!
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.
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"?
Works a treat!
Good video
Thank you!
Thanks!!!!!
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
@5:51 Your outlets have power switches?! Sliiiiiick
LOL. Yeah we're truly living in the future :)
Australia too... all our outlets are switched.