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.

Justin
  • 21
  • 1

1 Answers1

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.

goldilocks
  • 60,325
  • 17
  • 117
  • 234