2

[Previously asked this on Stackoverflow, but was told it was off-topic. I can't tell if it fits here or not after reading the guidelines, but figured I'd give it a try!]

I am new to raspberry pi, and I'd like to use node.js for GPIO projects. Nothing specific just yet - just learning how to control/read from various pieces of hardware for the time being. Eventually, I do plan on setting up a server to do GPIO stuff based on API requests.

There seem to be several modules/libraries to choose from to make that happen - so far, I've experimented with both Johnny-Five and onoff to write simple blinking LED programs.

Before I go too far down the rabbit hole with either one, what are some pros and cons? Does anyone have a strong opinion of one verses the other for a given application, or perhaps have a suggestion for a different module altogether?

If it matters, I'm running Raspbian Jessie on an RPI3.

  • What kind of things do you plan on doing with GPIO? Just turning things on or off? Just reading simple values? Or something with a more real time protocol? Please describe your needs better. – jfriend00 May 1 '16 at 16:20
1

I think the cons to using node.js directly with the GPIO's is, if some of the posts here are any indication, there isn't a well maintained full featured js library for doing so.

However, presuming js's file API is up to snuff (I haven't used node in years, but I'm sure it is by now), you can do elementary things via the sysfs interface directly. As mentioned there, there are some limitations, but you can certainly blink an LED (in fact, using that methodology I've managed to do poor quality software PWM to dim one).

Depending on your programming skills and knowledge of languages that do have strong Pi oriented GPIO libraries (i.e., python and C), my preference here would be to connect node as a client to a simple backend server; I think the pigpio library already has one that may be appropriate. This would be much like using a database that has a TCP based interface.

  • Why would you create another server to talk to GPIO rather than just talk to GPIO directly from node? The rationale behind that extra layer of complication is not obvious to me. I read temperature GPIO probes from my PI node server (home automation controller) and have no issues with that at all. I'm also curious why someone who hasn't used node in years is proposing this kind of answer to a question about node? – jfriend00 May 1 '16 at 16:07
  • 1
    @jfriend00 If there is a reliable, maintained js library out there that works for I2C and such, great -- please write an answer about it! The "rationale" though is a standard stacked architecture (personal preference). Having a backend database server is not the only way to access a db, but when node was first getting a lot of attention it was hyped paired with couchdb, so it certainly has the capacity to operate as part of such a stack. However, the biggest advantage of doing stuff that way comes out when a lot of concurrent action is going on, which obviously isn't the case here. – goldilocks May 1 '16 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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