I am trying to read the serialport data coming from Arduino to Raspberry PI but it doesn't display anything. I have verified that the data is arriving in the serialport. The same script works fine in windows 7. Also I have tried two different approaches of reading the serial data but none of them work. The node.js version I am using is v0.9.9.
Any help will be greatly appreciated.
var sys = require('sys');
var portName = '/dev/ttyACM0' ;
/////////////////////////////////////////////////
//Approach 1
/////////////////////////////////////////////////
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort(portName, {
baudrate: 9600
});
serialPort.on("open", function () {
console.log('open');
serialPort.on('data', function(data) {
//console.log('data received: ' + data);
sys.puts("here: "+data);
});
serialPort.on('error', function(message) {
console.log('error: ' + message);
});
});
/////////////////////////////////////////////////
//Approach 2
/////////////////////////////////////////////////
var serialport = require("serialport");
var SerialPort = serialport.SerialPort; // localize object constructor
var sp = new SerialPort(portName, {
parser: serialport.parsers.raw
});
sp.on("data", function (data) {
sys.puts("here: "+data);
});