title: Raspberry PI GPIO add_event_detect triggering multiple channels on one button press
body: <p><strong>Project:</strong>
  I am creating a light switch panel to control my LIFX WiFi lights. I have 3 buttons hooked up to GPIO pins 6, 20 and 22 and I'm using the GPIO.add_event_detect to capture when the button is pressed. </p>
  
  <p><strong>Problem:</strong>
  My issue is that if I push one button, <em>sometimes</em> it triggers one or more of the other channels. For example pressing button channel 6 will also trigger 20 and/or 22. The odd thing is that it works perfectly fine 80% of the time so I really don't believe its anything physical like signals crossing wires. I've been at this on and off for about 2 weeks.</p>
  
  <p><strong>What I've Tried:</strong> Originally I made a little protoboard which I soldered leads to a 40 pin header and I thought that there was a chance a wire was crossing causing this phantom button press. I then bought a $20 board off Amazon that has screw terminals for each GPIO pin... same issue. I tried switching up the GPIO pins I was using to be further apart on the board, in case somehow they were crossing.</p>
  
  <p>I've tried updating the GPIO library but I have the latest.</p>
  
  <p>I've tried different push buttons to see if they where faulty.</p>
  
  <p>I've checked that pressing one button doesnt wiggle the other buttons enough that they trigger.</p>
  
  <p>I've tried using GPIO.input(channel) to see if the button is pressed in the buttonPressed callback but more times than not that makes it so that no buttons are pressed (even the one I actually pressed).</p>
  
  <p>I've tried removing other code for the LIFX lan library and the TCP server that I start.</p>
  
  <p>The buttons are screwed into a piece of wood and have several inches between them so I know wires are not crossing there.</p>
  
  <p>Next I'm going to try swapping to another PI but I have everything screwed down into a cabinet and its difficult to get to.</p>
  
  <p><strong>Setup:</strong>
  Raspberry Pi 2 B+
  Python 2.7
  <a href="https://i.stack.imgur.com/Lao3l.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lao3l.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Code:</strong>
  I've omitted irrelevant code to make it easier to read</p>
  
  <pre><code>import os
  import sys
  from time import sleep
  import time
  import random
  import threading
  import json
  import itertools, glob
  from socket import error as SocketError
  from TcpClient import *
  from lifxlan import BLUE, CYAN, GREEN, LifxLAN, ORANGE, PINK, PURPLE, RED, YELLOW
  from itertools import cycle
  import RPi.GPIO as GPIO
  
  BUTTON_1 = 6
  BUTTON_2 = 20
  BUTTON_3 = 22
  
  # Setup Network
  HOST = ''
  PORT = 9998
  
  GPIO.setmode(GPIO.BCM)
  GPIO.setup(BUTTON_1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  GPIO.setup(BUTTON_2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  GPIO.setup(BUTTON_3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  
  lifx = None
  currentScene = None
  
  def stopScene():
      ...
  
  def setScene(lan, scene):
      ...
  
  def lightsOn(lan):
      ...
  
  def lightsOff(lan):
      ...
  
  class Message(object):
      ...
  
  class Client(threading.Thread):
      ...
  
  class Server(object):
      ...
  
  def buttonPressed(channel):
      global lifx
      global currentScene
      global BUTTON_1
      global BUTTON_2
  
      print("Button Pressed: " + str(channel));
  
  lifx = LifxLAN(None)
  print("Discovering Lights...")
  numLights = len(lifx.get_lights())
  print("Lights discovered: " + str(numLights))
  
  GPIO.add_event_detect(BUTTON_1, GPIO.RISING, callback=buttonPressed, bouncetime=1000)
  GPIO.add_event_detect(BUTTON_2, GPIO.RISING, callback=buttonPressed, bouncetime=1000)
  GPIO.add_event_detect(BUTTON_3, GPIO.RISING, callback=buttonPressed, bouncetime=1000)
  
  server = Server(HOST, PORT)
  server.start(10)
  </code></pre>
  
  <p><strong>Example Output:</strong> Pressing only button 6 (Left button in picture)</p>
  
  <pre><code>Discovering Lights...
  Lights discovered: 2
  [SERVER] Starting...
  [SERVER] Listening
  Button Pressed: 6
  Button Pressed: 20
  </code></pre>
  
  <p><strong>Example Output:</strong> Pressing only button 6 again</p>
  
  <pre><code>Discovering Lights...
  Lights discovered: 0
  [SERVER] Starting...
  [SERVER] Listening
  Event: 22
  Event: 20
  Event: 6
  </code></pre>