dany246
Posts: 11
Joined: Wed Jul 17, 2013 3:55 pm

Switching light in my house make noise to gpio

Thu Jul 18, 2013 10:41 pm

Hi everybody, i have two buttons connected one side to the gnd and the other side connected to the gpio 19 and 24, they works fine but when become evening and i switch on a light in my house (for example) the pi detects an input from one of those gpio and when i switch the light off same things... here is the script i use:

Code: Select all

mport RPi.GPIO as GPIO
from time import sleep
import os
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def Gate(channel):
    # Internal buttons to open the gate
    print 'Gate opened';
    #os.system("python /root/LCD/pint.py")
    #os.system("python /root/gate.py")

def Bell(channel):
    # External button to ring the bell
    print 'Bell rang';
    os.system("python /root/LCD/pout.py")
    os.system("python /root/bell.py")
    os.system("python /root/photo.py")

GPIO.add_event_detect(19, GPIO.RISING, callback=Gate, bouncetime=200)
GPIO.add_event_detect(24, GPIO.RISING, callback=Bell, bouncetime=200)

while True:
    # Here things to loop
    sleep(60);
Thanks for any help ;)

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: Switching light in my house make noise to gpio

Thu Jul 18, 2013 11:22 pm

Are you using pull-up resistors??

Richard S.

pksato
Posts: 295
Joined: Fri Aug 03, 2012 5:25 pm
Location: Brazil

Re: Switching light in my house make noise to gpio

Fri Jul 19, 2013 3:18 am

Hi,
insert small capacitor (10nF to 1uF) on parallel with button.
And/Or use a 1k to 10k external pull up resistor.
Wires to bottons are long?

dany246
Posts: 11
Joined: Wed Jul 17, 2013 3:55 pm

Re: Switching light in my house make noise to gpio

Fri Jul 19, 2013 9:25 am

redhawk wrote:Are you using pull-up resistors??

Richard S.
No
pksato wrote:Hi,
insert small capacitor (10nF to 1uF) on parallel with button.
And/Or use a 1k to 10k external pull up resistor.
Wires to bottons are long?
Wires are very long the wire that connect button connected to the pin24 about 15m and the other about 2m but i'm getting more interference on pin19.
Anyway i’m not sure to be able to use pull up resistor cause raspberry is far from the buttons and they are connected only to gnd and gpio.. There is no software way to eliminate this interference?

Thanks everybody for helping ;)

dany246
Posts: 11
Joined: Wed Jul 17, 2013 3:55 pm

Re: Switching light in my house make noise to gpio

Fri Jul 19, 2013 11:05 am

Electrolytic capacitors are fine? I just bought 2 from 10uF..

User avatar
Burngate
Posts: 6090
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Switching light in my house make noise to gpio

Fri Jul 19, 2013 11:27 am

dany246 wrote:Anyway i’m not sure to be able to use pull up resistor cause raspberry is far from the buttons and they are connected only to gnd and gpio.. There is no software way to eliminate this interference?
The pull-up resistor (and capacitor) doesn't have to be by the button - it can be right on the Pi. But, yes, you can enable pull-ups internally to the Pi in software

dany246
Posts: 11
Joined: Wed Jul 17, 2013 3:55 pm

Re: Switching light in my house make noise to gpio

Fri Jul 19, 2013 11:45 am

Burngate wrote:The pull-up resistor (and capacitor) doesn't have to be by the button - it can be right on the Pi. But, yes, you can enable pull-ups internally to the Pi in software
Well so what do I have to add in my python code? Anyway if resistors and capacitors have to be near the pi I can use them, but if there is a software way it could be better

Thanks a lot for helping ;)

dany246
Posts: 11
Joined: Wed Jul 17, 2013 3:55 pm

Re: Switching light in my house make noise to gpio

Fri Jul 19, 2013 12:44 pm

I just tried with the capacitors and for pin 24 it works!! But for pin 19 nothing to do :( i will try now with pull up resistors, hope i have understand how they works ahah

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Switching light in my house make noise to gpio

Fri Jul 19, 2013 2:25 pm

Welcome to floating inputs ;)

Pull up (or pull down) resistors are the way to go. You can use the built in ones by tweaking the code or use separate physical resistors.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

dany246
Posts: 11
Joined: Wed Jul 17, 2013 3:55 pm

Re: Switching light in my house make noise to gpio

Fri Jul 19, 2013 3:47 pm

Well i used in my script

Code: Select all

GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
But it doesn't seems to work

dany246
Posts: 11
Joined: Wed Jul 17, 2013 3:55 pm

Re: Switching light in my house make noise to gpio

Fri Jul 19, 2013 5:52 pm

Well this way seems to work correctly :D
Image

User avatar
jackokring
Posts: 816
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
Contact: ICQ

Re: Switching light in my house make noise to gpio

Fri Jul 19, 2013 5:57 pm

The insulation of free space is measurable with a high enough impedance. Hence pull-ups to lower the impedance to something smaller.
Pi[NFA]=B256R0USB CL4SD8GB Raspbian Stock.
Pi[Work]=A+256 CL4SD8GB Raspbian Stock.
My favourite constant 1.65056745028

Return to “General discussion”