Tim Daneliuk tundra at bogus-city.tundraware.com
Mon Aug 31 21:07:58 CEST 2015

On 08/16/2015 02:40 PM, John McKenzie wrote:
>  Hello, all. I am hoping some people here are familiar with the RPi.GPIO 
> python module for the Raspberry Pi.

I am not familiar with the module, but I am quite familiar with dealing
with hardware interfacing, mostly in assembler.

One thing you need to ensure is that either the module or your
code implents software debounce.  When a button is pressed or switched moved,
there is mechanical bounce for a some period of time immediately thereafter.
In the time right after the switch/button is pressed, the mechanical closure
"bounces" between "on" and "off" for a little while, until it settles down
to the position you've selected.

The idea is to use the initial change of state to initiate the button handling logic but
wait until the switch/button settles down to it's final (and therefore, reliable) state. 

One algorithm to do this is to wait a fixed amount of time after the initial event - say,
100ms - before reading the switch.  The other way to do is to read the button/switch state
ever few milliseconds and only accept the input if it has not changed in, say,
5 measurements.


More information about the Python-list mailing list