Basically I have 6 push buttons setup as HIGH input, with internal pull up resistor enabled through software. On the breadboard, each GPIO pin are connected -> push button -> GND (no external resistor/capacitor). So below the button is pushed, it is HIGH (3.3V), when it is pushed, the signal will sink to LOW. So when you release the button, the RISING edge detection will trigger the callback interrupt. I also added 100ms to debounce the switch, which can be seen in the code below.
Code: Select all
import RPi.GPIO as GPIO
b11_count = 0
def callback_11(channels):
global b11_count
b11_count += 1
print 'b11_count = %d' %(b11_count)
def callback_x(channels):
print 'other buttons'
print 'start'
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(11, GPIO.RISING, callback=callback_11, bouncetime=100)
GPIO.add_event_detect(13, GPIO.RISING, callback=callback_x, bouncetime=100)
GPIO.add_event_detect(15, GPIO.RISING, callback=callback_x, bouncetime=100)
GPIO.add_event_detect(16, GPIO.RISING, callback=callback_x, bouncetime=100)
GPIO.add_event_detect(18, GPIO.RISING, callback=callback_x, bouncetime=100)
GPIO.wait_for_edge(12, GPIO.FALLING)
print 'bye'When I push button #11 once, I expect the screen would just print the counter once. And when I keep pushing the same button multiple times the counter on the screen will increment in proper order. However in my test when I pushed button #11 once (press-release within 1 second), I found multiple lines of counter were printed on the screen and the values are out of order. Please see the attached picture.
Increasing the bounce time to 500ms help sometimes, but once in a while I still get the same problem. I had also tried 1000ms, the system become sluggish but still I cannot eliminate the problem completely. What else can I do? Please advice