Yun + NodeJS Questions

I was successful in installing NodeJS on the Arduino Yun, however, I'm having a little trouble understanding how to make it useful I guess. I've read lots of posts about using node to control the arduino board, but all of them had NodeJS installed on a computer and a firmata sketch that would allow communication between the computer and the board.

My ultimate goal is to have node with websockets and host a web server on the yun to host a webpage to display real time data (temperature, light, motion, etc) and to respond to commands coming from the webpage.

I guess the first thing I'd like to figure out is... ok, so I have node installed, how can I write a script to, lets say, read the temperature or light sensor? Can Johhny Five be installed on the Yun?

Thanks!

I'm sorry, but I don't know anything about node.js or Johnny Five. But I suppose what you want to do is possible. I'm responding because while the problem in that thread is something unrelated, there was a recent discussion where someone stated he was running Node, Johnny Five, and Firmata on a Yun: http://forum.arduino.cc/index.php?topic=353567.msg2438499#msg2438499

naner13:
::::SNIP::::

I guess the first thing I’d like to figure out is… ok, so I have node installed, how can I write a script to, lets say, read the temperature or light sensor? Can Johhny Five be installed on the Yun?

Thanks!

@naner13,
The answer to both your questions is Yes. However, Johnny-Five is not really that useful. Johnny-Five was intended for systems that have a weak serial port interface. The interface to the Arduino library is fairly strong, and rarely requires tweaking.

I am not a fan for Firmata, but I will give it neither a Yea, nor a Nay. For my taste, there is not enough granular control.

Next, week I’ll be starting a new project that uses simple resistor-type sensors with the Yun. Your question will be one that I am directly answering, so if you have some questions, this is a good time to ask. Especially since we have the attention of ShapeShifter. :wink:

Jesse

Thank you guys.

@jessemonroy650, I haven't gotten far enough to find out the questions I really want to ask, I'm having trouble making firmata work. Since npm doesn't work on the Yun (not enough ram), I downloaded the git repository for firmata and copied the lib folder to the Yun, it didn't work right away because the dependencies weren't there, so I also downloaded the es6-shim and copied to the Yun.

Also, I commented out the following line on the etc/inittab file and tested serialport on node (it worked fine):

ttyATH0::askfirst:/bin/ash --login

Now as far as firmata, here's the code:

var Board = require("firmata");
var board = new Board("/dev/ttyATH0", function() {
  // Arduino is ready to communicate
  console.log("abc");
});

Well, the problem is it never gets to "abc"... but, if I change the port name to something else (say xyz) it tells me the port was not found (meaning firmata was successfully loaded I guess).

Any ideas? Anyway I can debug it in more detail to figure out what the problem is?

Thanks!!

Ok, I think I had misunderstood how the whole communication actually worked. I didn't know that in order for firmata to work on node there needed to be a firmata sketch on the Arduino (duh...). At least here's a bit of useful information, the StandardFirmata will not work on the Yun once you disable the port on inittab, Serial has to be changed to Serial1 on the sketch. Here's a modified version that worked for me:

I have been able to read sensors and have started to play with node's express ON the Yun by setting up a web server, it's fast, and so far from what I've noticed (not tested) it's faster than the out of the box web api. We'll see how it goes... one thing I couldn't figure out is how to change the analog reference to internal using firmata.