Skip to content Skip to sidebar Skip to footer

How To Disable Raspberry Pi Gpio Event For Certain Time Period After It Runs In Python?

I am creating an event whenever my Raspberry Pi's GPIO pin has a falling edge. However, I want to disable this event for a certain amount of time (5 seconds for example) after each

Solution 1:

There is a switch bounce effect which happens when we use simple cheap buttons with just two contacts connected to GPIO.

During the press and depress alot of analogue stuff happens which do not belong to digital domain.

There are two ways to solve those bounces :

  • hardware way (adding RC filters)
  • software way - wait for some time to filter out those analogue world effects (this could be "dummy delay", "usage of state machines", "temporary disable interrupt")

Fortunaly python GPIO library supports software implementation for debouncing.

When you define callback for such "interrupt" you can specify the time for which listener go deaf to any changes on specified pin.

It does not really matter whether you use "bad"( noisy) button or not. You can use this debouncing built-in function to achieve what you need:

GPIO.add_event_detect(21, GPIO.FALLING, callback=event, bouncetime=5000 )

Post a Comment for "How To Disable Raspberry Pi Gpio Event For Certain Time Period After It Runs In Python?"