Reply To: Simple 1 button GPIO on off switch: 1 switch, 2 wires, 10 lines of code

Home Forums RetroPie Project GPIO Adapter, ControlBlock etc. Simple 1 button GPIO on off switch: 1 switch, 2 wires, 10 lines of code Reply To: Simple 1 button GPIO on off switch: 1 switch, 2 wires, 10 lines of code

#121579
Profile photo of kiwijam777
kiwijam777
Participant

It worked for me until it didn’t for one particular switch. After troubleshooting I found out there was an error in the code; it didn’t need the line to go “high” since the 6 pins on that end are always high. Try this one:
Create a file called “/home/pi/scripts/shutdown.sh”
Inside the file, type.

#!/bin/bash
echo “3” > /sys/class/gpio/export
echo “in” > /sys/class/gpio/gpio3/direction
while [ “$(cat /sys/class/gpio/gpio3/value)” != ‘0’ ]
do
sleep 1
done
poweroff &
exit 0

Remember you still have to refer to this file in RC.local

ADD SCRIPT TO LOAD AT STARTUP BY ADDING COMMAND TO /ETC/RC.LOCAL:
sudo nano /etc/rc.local
TYPE THE FOLLOWING IN RC.LOCAL AFTER THE LINE “#By default this script does nothing”:
sudo /home/pi/scripts/shutdown.sh &

If you still can’t get it, I will email you the files.

Skip to toolbar