Power switch without powerblock?
-
Raspberry Pi 3b+
RetroPie 4.4Is there a good way to connect a power switch to my pi without a powerblock, Mausberry or other third party devices? I have looked high and low and there are a lot of different videos and ideas out there. What is the best/easiest solution that people have had luck with.
I have this latching 5 prong power button and was hoping to not spend another $27 just to power the thing on/off. Looking to use a cabinet mounted button and not one that is built into the power cable
Any help/links are appreciated.
-
@ayekaye Sure, you can do it yourself by connecting the button to 2 GPIO pins, there are plenty of resources for how to do it - for instance https://gilyes.com/pi-shutdown-button/ on how to use 1 button for shutdown/start using a simple script and wiring the button to the 5 and 6 pins.
-
Your power button LED is designed for 12V, so just wiring it straight to the GPIO pins, and using the 5V pins to power the LED may not give you enough voltage to illuminate it. I certainly agree with you about trying to avoid $27 for a power switch on a $35 computer though.
-
@mitu Looks like this is for a momentary button and not a latching button?
-
@ayekaye Yes, but I think the script can be adapted so it reads when the button is pressed/depressed. In your case, press=on, depressed=off (initiate shutdown).
-
@mitu @ayekaye
I will include this solution also in the multi switch script here.. Then I will add option to use momentary and/or latching button. That's no problem! It will be written in bash and we will need justraspi-gpio
installed viasudo apt install raspi-gpio
Then I think the script can be pushed to version 1.0, as three or five people tested and it works as it should.
Save shutdown with all metadata saved ;)
And yes you are right @mitu... Take a look at line 260 here - I once used this for handling these two types of buttons.
-
@cyperghost said in Power switch without powerblock?:
@mitu @ayekaye
I will include this solution also in the multi switch script here.. Then I will add option to use momentary and/or latching button. That's no problem! It will be written in bash and we will need justraspi-gpio
installed viasudo apt install raspi-gpio
Then I think the script can be pushed to version 1.0, as three or five people tested and it works as it should.
Save shutdown with all metadata saved ;)
And yes you are right @mitu... Take a look at line 260 here - I once used this for handling these two types of buttons.
Is there a step-by-step guide on how I could accomplish adding a latching switch to the pi with programming needed? I apologize I am not technical enough for that thread I do not think.
-
@ayekaye No there is a step by step guide and there will no programming skills needed as the script automatically detects the right button. You need just a SSH connection or a keyboard conntected to the Pie (prefer SSH because you'll copy and paste some lines of code). So don't be hostile to technics ;)
-
@mitu @ayekaye
Okay done ... Multi Switch Shutdown Script v 0.50 released
I introduced--generic
command. You can use latching and momentary switch with this script both work fine. I used GPIO3 as default button. All you need it to connect switch to GPIO3 and common ground (Physical Pin 5 and 6). Connection shema can be taken from here....How to install
- Login with SSH
- Install raspi-gpio with
sudo apt install raspi-gpio
- Type in command
mkdir /home/pi/RetroPie/scripts && cd /home/pi/RetroPie/scripts
- DL:
wget https://raw.githubusercontent.com/crcerror/ES-generic-shutdown/master/multi_switch.sh && chmod +x multi_switch.sh
- Now edit ES autostart with
nano /opt/retropie/configs/all/autostart.sh
and add script to like .... /home/pi/RetroPie/scripts/multi_switch.sh --generic &
but BEFORE the last line emulationstatio #auto- Give me some feedback ;)
Please remove/disable other shutdown scripts before installing this!
-
@cyperghost Nice work ! Now all you need is a proper service (systemd) to get rid of this hacks with the autostart file. Bonus: it will run as root directly so no more
sudo this & that
. -
@mitu Hehe ;) Well I don't like services ... therefore I exposed OnOff SHIM
No, really this tool is intended to work from command line with it's--es-pid --closeemu
commands so it's just a script that might get into autostart somehow.....
Besides: You can use parameters--es-pid
and--rc-pid
to detect if ES is running or if runcommand (= emulator) is running. Then you can use python for further handling.EDIT:
I like the autostart that ES provides! It's a good entrypoint for adding some scripts easily. So why not make use of them? I wasn't aware that the raspi-gpio tool does not need sudo right so out 3 of the 5 devices do not need root rights ;) -
Just made use of your mult_switch.sh script.
I'm using it for a momentary switch on a 3B running retropie 4.4.1
Worked great thanks.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.