Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button debouncing #27

Closed
chatmurai opened this issue Nov 17, 2014 · 4 comments
Closed

Button debouncing #27

chatmurai opened this issue Nov 17, 2014 · 4 comments

Comments

@chatmurai
Copy link

Hi there,

Nice GPIO library !
Is there any internal mechanism for debouncing the hardware interrupts watch() function? I am having issues with this, and found nothing to get rid of it.

@fivdi
Copy link
Owner

fivdi commented Nov 17, 2014

Hey @8power8, thanks.

The constructor has an option called debounceTimeout. Here is an example of it's usage which works for me:

var Gpio = require('onoff').Gpio,
    button = new Gpio(4, 'in', 'falling', {
        debounceTimeout : 50 
    }),
    count = 0;

button.watch(function(err, value) {
    if (err) throw err;
    count += 1;
    console.log('button released ' + count + ' times');
    if (count === 500) {
        button.unexport();
    }
});

The circuit is similar to this one here, except that the button is wired to GPIO4 rather that GPIO17. Note that the 10KΩ resistor is actually quite important. If it's not there, small movements of the button or the wire connecting the button to GPIO4 can result in tens of unauthentic interrupts.

@fivdi
Copy link
Owner

fivdi commented Nov 17, 2014

Hmm, if you're using the BeagleBone Black, you could give this Button a try. Internally it uses the Linux gpio-keys driver for detecting button events. The gpio-keys driver also supports software debouncing.

@chatmurai
Copy link
Author

It works like a charm.
I followed your advice and changed my circuit wiring to a 10KΩ solo resistor instead of 10KΩ + 1KΩ like this one, and this works great too.
One never says thank you too much, so again thanks for this module 👍

@fivdi
Copy link
Owner

fivdi commented Nov 18, 2014

That's nice to hear. I guess the issue can be closed.

@fivdi fivdi closed this as completed Nov 18, 2014
@fivdi fivdi mentioned this issue Dec 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants