Close

Button Debounce Updates

A project log for Music Button

Raspberry Pi Zero plays an audio clip when a button is pushed.

ehunckehunck 04/18/2019 at 04:120 Comments

This is just a comment on some testing that I was doing.  It seems that the previous method for debouncing this button, using following code did not work as desired.

GPIO.add_event_detect(10, GPIO.RISING, callback=button_callback, bouncetime=200)

I wanted to detect a rising edge pulse coming from my button indicating that the button had been released.  

With the code above, a single button press ( HIGH to LOW then LOW to HIGH) could potentially trigger two button press events if the user paused for a second while the button is being pressed before releasing.  The behavior of the above "bouncetime" seems to prevent signal bounce from causing callbacks for the given time, but it does not necessarily capture the proper number of button presses.

I found that others have noticed this as well on the internet.  A good Q&A link that has a great answer with code is linked here: Stack Exchange Raspberry Pi Link.

I ended up just using the code that was selected as the answer in that article to implement my button debounce, and it works well.

Discussions