I want to add a on/off switch to my pi 2 to correctly shut the pi down
This is the switch I want to add:
Edit: moved from a link to be included below:
This guy in a Raspberry Pi kik group made this code for me
Edit - reproduced below:
#!/usr/bin/python3 import RPi.GPIO as g from time import sleep from subprocess import Popen g.setmode(g.BCM) g.setup(26,g.IN) def p26_callback(channel): command = ['/usr/bin/sudo','poweroff'] Popen(command) g.remove_event_detect(channel) # we've done it once, stop watching return g.add_event_detect(26, g.FALLING, callback=p26_callback) try: sleep(30) finally: g.cleanup()
but he didn't explain how to wire it up. Also I have no idea how to add the code to the pi.
I'm running kali. I haven't tried to wire the switch or put the code in the pi because I do not know how to.