Mother needs help with Push Button GPIO
Posted: Fri Nov 25, 2016 8:23 pm
First off, I am a beginner in programming, so have some faith in me
I started with Raspberry after my kids got a kit for christmas. I have searched for a solution, but found none. Also error-searching to try fix it my self have been 20+hours, so I really hope some clever heads can guide me.
The problem:
I have a TV connected to a Raspberry Pi 3. From the Raspberry I have connected a pushbutton that turns ON/OFF the Raspberry. The pushbutton is connected to GPIO3 and GROUND (5,6) (no resistors, just cables from GPIO and to my pushbutton. Every thing works perfect, except when I connect something to a close powersocket, like my scrapping glue gun / heating machine. When I do this, the Raspberry shuts down, looks like Ive pressed the Push button to turn it off. I think it has to be a power disturbance for the Raspberry messing up?
Also I figure this has something to do with my script (?), and maybe I need to put a delay on it somehow? So that when the Raspberry gets the power disturbance, it will overlook it since it only was there for under a second. Am I on the right path here?
This is the python script Im using. Please help my modify it so that the Raspberry stops shutting down ramdomly when something is disturbing the power.
#!/bin/python
# Simple script for shutting down the raspberry Pi at the press of a button.
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN, pull_up_down = GPIO.PUD_UP)
# Our function on what to do when the button is pressed
def Shutdown(channel): os.system("sudo shutdown -h now")
# Add our function to execute when the button pressed event happens
GPIO.add_event_detect(3, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
# Now wait!
while 1: time.sleep(1)
The problem:
I have a TV connected to a Raspberry Pi 3. From the Raspberry I have connected a pushbutton that turns ON/OFF the Raspberry. The pushbutton is connected to GPIO3 and GROUND (5,6) (no resistors, just cables from GPIO and to my pushbutton. Every thing works perfect, except when I connect something to a close powersocket, like my scrapping glue gun / heating machine. When I do this, the Raspberry shuts down, looks like Ive pressed the Push button to turn it off. I think it has to be a power disturbance for the Raspberry messing up?
Also I figure this has something to do with my script (?), and maybe I need to put a delay on it somehow? So that when the Raspberry gets the power disturbance, it will overlook it since it only was there for under a second. Am I on the right path here?
This is the python script Im using. Please help my modify it so that the Raspberry stops shutting down ramdomly when something is disturbing the power.
#!/bin/python
# Simple script for shutting down the raspberry Pi at the press of a button.
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN, pull_up_down = GPIO.PUD_UP)
# Our function on what to do when the button is pressed
def Shutdown(channel): os.system("sudo shutdown -h now")
# Add our function to execute when the button pressed event happens
GPIO.add_event_detect(3, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
# Now wait!
while 1: time.sleep(1)