2

Background

I am trying to learn how to use the rpio library (https://github.com/jperkin/node-rpio) in my nodejs application.

What do I want to do

So far I have been able to test the blink led example form the documentation, and I was trying to do the push button test ("Poll a button switch for events" as is it called at the documentation). I had copied the content of the example and tried to execute it both when a page loads, to execute it on the server-side through a post request, and tried also in simply executing it when the server starts. Here is the code:

rpio.open(15, rpio.INPUT, rpio.PULL_UP);

function pollcb(pin)
{
        /*
         * Wait for a small period of time to avoid rapid changes which
         * can't all be caught with the 1ms polling frequency.  If the
         * pin is no longer down after the wait then ignore it.
         */
        rpio.msleep(20);

        if (rpio.read(pin))
                return;

        console.log('Button pressed on pin P%d', pin);
}

rpio.poll(15, pollcb, rpio.POLL_DOWN);

I am using the circuit schematic as shown at the image below: source:https://github.com/raspberrypilearning/physical-computing-guide/blob/master/pull_up_down.md

The difference is that I dont have the switch, but I guess that just using wires to simulate the pessing of a button will do it

The problem

It is not working at all... Everytime when I call the function, my ssh command line gets stuck for 5-10 seconds and then my connection to the raspberry pi is reset, not allowing me to connect to the raspberry again; and then I have to unplug the raspberry to restart it! It is like the whole board collapses when I try to do this approach, which is also concerning me about the fact that I have to shut down my raspberry not in a safe way, what can consequently corrupt my sd card.

edit: It looks like that whenever I try to execute the rpio.poll function, it breaks the application and the board.

I appreciate any possible help about this issue.. Thank you!

6
  • Does RPIO actually run on the Pi you are using? Do you need to be running it with root access? Have you asked the author?
    – joan
    Jul 10, 2019 at 19:58
  • Hello, are you using the 3.3v from the Pi for your circuit or is is a separate supply? Have you double checked the resistor values you're using? Jul 11, 2019 at 9:25
  • @joan yes it does, it is saying in the documentation that it supports the b+ model. Jul 11, 2019 at 10:25
  • @RogerJones hey Roger, I am using the 3.3V from the Pi. Yes, I have double checked for sure! Jul 11, 2019 at 10:26
  • Just re-read your question and noticed that running the command crashes the Pi, not pressing the button. My mistake: I was worried you had the wrong resistors and were essentially shorting the 3.3v supply to ground. Anything of note in the system log when you restart? Jul 11, 2019 at 11:20

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.