Shutdown Raspberry via GPIO
I'd like to shut down my Raspberry Pi 3 via a Button connected to a GPIO.
Therefore i connected a button and wrote a script like in the link below (i used the while loop as in listing 2).
This works perfectly as long as i don't connect the printer (megatronic board) to the USB-port. When the printer is connected, the pi shuts down randomly after 0 to 60 sec just like as if the button is pressed. When i stop the python script the printer works fine.
I tried everything i could imagine to fix this. I used different GPIO pins, tried internal and external pullups and i checked the wiring often.
So the button works fine and the printer works fine but i can't use them at the same time.
Is the connection to the printer messing with the GPIOs?
I'm using 0.80.3 and the latest raspbian jessie by the way.
from subprocess import call
print "Button Pressed"
GPIO.add_event_detect(17, GPIO.RISING, callback = Interrupt, bouncetime = 250)
# nix Sinnvolles tun
input_state = GPIO.input(17)
if input_state == False:
os.system("sudo shutdown -h now")