Introduction: Physical Shutdown Button for Raspberry Pi
Sometimes I wondered, there should be a physical shutdown button on raspberry pi, to safely down the device, because direct shutdown of raspberry pi could damage the SD card or File system. SO i added of my own. Here is how.
added a push button to BCM GPIO 23. Another end of Push button to the 3.3V that is Pin Number One.
write two code, one is python to read continuously the Gpio 23, and other shell script to run the python file. and
put the shell sctipt to the crontab to start on system reboot.
To install software on Your RPI board.
1. Download the code, By typing bellow command on your shell window.
"git clone https://github.com/embeddedhacks/physicalShutdown" ---> without quote "" else you can find the code bottom of this article.
give executable permission to both the file by chmod +x filename.py
2. Open the lunchshutdown.sh file,
and give the path of the shutdown.py file, and save it.
3. Crontab is a demon which starts when RPI boot, it runs in background. we have to add our code to crontab to run continuous in background. Open crontab, By following command
"sudo crontab -e4"
Add the following line at bottom of the crontab
"@reboot sh /home/pi/Your/filePath/lunchShutdown.sh"
Then save the crontab by ctrl+x5.Then Simply reboot the system.
Now Power on you RPI. The lunchshutdown.sh will run in background automatically.
Once you will press your button. It will Shutdown Your device safely.
Here is a video , which i am running on my device.
If You have doubt regarding installation and code, You can comment bellow. Thanks. Happy Learning.
We have a be nice policy.
Please be positive and constructive.