Hi guys, this is the method I am going to employ with my GBZ. I cant be bothered dealing with the hassle of using a slide switch when this method is so much simpler.
Basic premise is using a momentary push button switch instead of a slide switch to turn the pi on and off. This switch will ground GPIO3 board pin 5 to its neighbor pin 6. There will be a python script running in the background that see's this even has taken place, and then issue a shutdown command. Once shut down, depressing this switch once again will boot the pi.
I'm planning on putting a switch elsewhere to mechanically disconnect the battery or power supply for periods of non use.
For the momentary button, I have found that the long stemmed tactile switchers Wermy uses as L and R buttons actually press nicely into the bottom of the standard gameboy slide switch cap, and there is enough slack in the area to allow it to act as a push button, assuming the base of the tactile switch is mounted appropriately. So my GBZ will simply require a press on the slide switch, rather than a slide.
Button has a 2 second hold delay for shutdown, to avoid accidental shutdowns.
apt-get with the following command (this is assuming you have your pi connected to the internet):
Code: Select all
sudo apt-get install update
sudo apt-get install python3-gpiozero
call our script shutdown.py (it is written in python). Create and edit the script by doing:
Code: Select all
sudo nano /root/shutdown.py
The content of the script: Paste it in the blank area
Code: Select all
from gpiozero import Button
from subprocess import check_call
from signal import pause
def shutdown():
check_call(['sudo', 'poweroff'])
shutdown_btn = Button(3, hold_time=2)
shutdown_btn.when_held = shutdown
pause()
You can do this with the following:
Code: Select all
sudo nano /etc/rc.local
Code: Select all
python /root/shutdown.py &