0

I am building a simple application with a switch on the rasperry pi 3 b+. I have connected GPIO pin 18/32 through a 56k resistor to 3.3v (tried pin 1 and 17) to have it pulled up. The switch closes the GPIO to GND when pressed. This works fine so far.

I use it as follows:

GPIO.setup(23, GPIO.IN)
GPIO.add_event_detect(23, GPIO.FALLING, callback=btn, bouncetime=200)

However, when I trigger the light switch of the ROOM, it generates random inputs and calls the btn() callback.

I am not sure what is wrong. Did I realize the pull down correctly? Is it the wrong capacity?

  • I am not sure what is wrong - neither are we, because we don't know what you DID. What is pin 18/32? What is connected to what? – Milliways Dec 28 '18 at 22:42
  • Are the room lights LED or incandescent? ... Some LED lights may create RF interference. In any case, any wire is an antenna... so, proper grounding and short wires are always a good idea... along with capacitors connected to a ground plane which short RF noise to ground rather than the circuit. – RubberStamp Dec 29 '18 at 1:51
0

You might try changing your bouncetime variable. I doubt that it is electrical interference -- you stated that it only produces the unwanted behavior when you use the switch and the bouncetime variable is used to 'debounce' the switch, so the time you are using is not sufficient. Increase it until the behavior goes away.

  • 1
    The room switch that causes the random inputs is actually the switch in the wall that turns on/off the light in the room. It is not at all connected to the pi. But in the meantime I was thinking about increasing the bouncetime to a reasonable value: I think I can expect the user to press the button longer than the interference from the room light switch may cause – ddd Dec 29 '18 at 18:43
  • The bouncetime variable has nothing to do with how long the switch is pressed -- it is related to the noise that is present on the GPIO bus --specifically pin 23 in your case. There is a difference. – jinzai Dec 29 '18 at 23:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.