toschi
Posts: 2
Joined: Mon Dec 28, 2015 12:27 pm

GPIO - Button triggers itself

Mon Dec 28, 2015 12:35 pm

I use a button to load a playlist in mpc and start playing. I've connected the button to GPIO 23 and the 3.3V with internal pull_down enabled, but I've also tried internal and external pull_downs and pull_ups (connected to GND instead of 3.3V).
In all cases the button press gets recognised fine and everything works perfectly.

Unfortunately, changes in our house (like powering off a computer or lowering motorised shades) also trigger the button press events.

Can anyone tell me why this happens and how to counter it? As I said, I've enabled internal pull_down so it shouldn't be a case of a floating input...

Thank You,
Peter

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: GPIO - Button triggers itself

Mon Dec 28, 2015 12:50 pm

How long is the cable between the button and the Pi?

There are two routes for electromagnetic interference (EMI) to get into the Pi: through the button cable or through the power cable. If the button cable is very long then it should be shielded.

For the power cable you could try fitting an EMI filter either between the mains plug and socket or you can make one yourself with a ferrite ring. See this example on Amazon. Only fit one of these where the current flow is balanced -- current in = current out, like on the power cable.

gordon77
Posts: 4077
Joined: Sun Aug 05, 2012 3:12 pm

Re: GPIO - Button triggers itself

Mon Dec 28, 2015 1:26 pm

If using edge detection could you rewrite you code to check the input to see if it's been pressed for a longer time instead?

RDS
Posts: 712
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: GPIO - Button triggers itself

Mon Dec 28, 2015 1:56 pm

Could I ask Peter, is mpc a type of mp3 player?

Mod Edit (rurwin): To avoid pulling the thread off-topic, mpc appears to be part of a music-playing app. See: http://linux.die.net/man/1/mpc

toschi
Posts: 2
Joined: Mon Dec 28, 2015 12:27 pm

Re: GPIO - Button triggers itself

Tue Dec 29, 2015 4:51 pm

Hello,
thanks for all the replies. the wire between pi and switch is about 8 inches long and yes, I use edge detection.

I think I have a ferrit core lying around somewhere. I will try that and reprogram to detect longer presses.

I don't want to go off-topic so here's just a short line about mpc: I use the pi as a music player and use a "volumio" image - just google it.

Return to “Python”