I use this to detect momentary button (connected to GPIO) press :
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def my_callback(channel):
print channel
GPIO.add_event_detect(18, GPIO.RISING, callback=my_callback, bouncetime=300)
raw_input()
Even with the debouncing thanks to bouncetime=300, I often get 2 messages instead of just 1 for a single button press.
How to detect properly one button press ?