Skip to main content
Tweeted twitter.com/StackRaspi/status/702657035779907584
added 75 characters in body
Source Link
Jacobm001
  • 11.9k
  • 7
  • 47
  • 57

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: A Single Pole Snap action chrome-like switch with a plate bearing the words "On" (on a Red background) and "Off" (on a black background) with wires going off out of the picture

This guy in a Raspberry Pi kik group made this code for me

http://pastebin.com/WTeR39d8

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()
#!/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.

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: A Single Pole Snap action chrome-like switch with a plate bearing the words "On" (on a Red background) and "Off" (on a black background) with wires going off out of the picture

This guy in a Raspberry Pi kik group made this code for me

http://pastebin.com/WTeR39d8

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.

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: A Single Pole Snap action chrome-like switch with a plate bearing the words "On" (on a Red background) and "Off" (on a black background) with wires going off out of the picture

This guy in a Raspberry Pi kik group made this code for me

http://pastebin.com/WTeR39d8

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.

Included image and code from links directly in post, added python tag
Source Link

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 This is the switch I want to addlink to be included below: A Single Pole Snap action chrome-like switch with a plate bearing the words "On" (on a Red background) and "Off" (on a black background) with wires going off out of the picture

This guy in a Raspberry Pi kik group made this code for me

http://pastebin.com/WTeR39d8

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.

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

This guy in a Raspberry Pi kik group made this code for me

http://pastebin.com/WTeR39d8

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.

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: A Single Pole Snap action chrome-like switch with a plate bearing the words "On" (on a Red background) and "Off" (on a black background) with wires going off out of the picture

This guy in a Raspberry Pi kik group made this code for me

http://pastebin.com/WTeR39d8

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.

how How can iI add thean On-Off switch to my raspberry piRaspberry Pi 2

I want to add a on/off switch to my pi 2 to correctly shut the pi down   

theThis is the switch I want to add this

This guy in a raspberry piRaspberry Pi kik group made this code for me

http://pastebin.com/WTeR39d8

but he didn't explain how to wire it up. also Also I have no idea how to add the code to the pi. im

I'm running kali http://pastebin.com/WTeR39d8. I haven't tried to wire the switch or put the code in the pi because I do not know how to.

how can i add the switch to my raspberry pi 2

I want to add a on/off switch to my pi 2 to correctly shut the pi down  the switch I want to add this guy in a raspberry pi kik group made this code for me but he didn't explain how to wire it up. also I have no idea how to add the code to the pi. im running kali http://pastebin.com/WTeR39d8. I haven't tried to wire the or put the code in the pi because I do not know how to.

How can I add an On-Off switch to my Raspberry Pi 2

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

This guy in a Raspberry Pi kik group made this code for me

http://pastebin.com/WTeR39d8

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.

edited tags
Link
Steve Robillard
  • 34.9k
  • 18
  • 104
  • 109
Loading
Source Link
laxus
  • 69
  • 3
Loading