jperkin / node-rpio

Raspberry Pi GPIO library for node.js
857 stars 123 forks source link

Poll function is freezing raspberry PI B+? #99

Closed JohnnyHandy closed 5 years ago

JohnnyHandy commented 5 years ago

I am sorry if this question is antiquate, but what is the proper circuit used to ellaborate the push button example? I am running into trouble when I try to make it work, and I am almost certain that I might be connecting things wrongly on my breadboard...

Edit: I found this guid: https://github.com/raspberrypilearning/physical-computing-guide/blob/master/pull_up_down.md and I am using the circuits that are being show at it. However, it does not work. It looks like that whenever I use the rpio.poll, my server-side application (which I am using nodejs and express to serve it) breaks, and I am forced to restart my raspberry... Anyone know any fix to it?

Edit2: I am using the following code to execute the polling function whenever the server starts:

http.listen(3000,'0.0.0.0',function(){
    console.log('server on')
    rpio.open(15, rpio.INPUT, rpio.PULL_UP);
    rpio.poll(15,buttonPress,rpio.POLL_DOWN);
})

the function "buttonPress" :

function buttonPress(pin){
        rpio.msleep(200)
        if(rpio.read(pin)) return
        console.log('button pressed')
}
JohnnyHandy commented 5 years ago

Unfortunately I was not able to put it to work using the rpio.poll function

However, I managed to listen to the input pin by using a setInterval() method:

function status(){
    rpio.open(15, rpio.INPUT, rpio.PULL_UP);
    setInterval(function(){
        var status = rpio.read(15)
        console.log(status)
    },1000)
}

I did try to listen every second, which was enough for the purpose in which I wanted to work, but if anyone try with a smaller interval, it might work as well.