2

I'm trying to bypass Bridge library and read serial directly from nodejs. I'm on the last sys upgrade (1.3) I have correctly installed nodes and serial module via opkg install. I have also commented out the line in the /etc/inittab:

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

This is my arduino code:

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("dudee");
  delay(100);
}

This is my node.js code:

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort("/dev/ttyATH0", {
    baudrate: 9600,
    dataBits: 8,
    parity: 'none',
    stopBits: 1,
    flowControl: false
}, false);

console.log("hello");

serialPort.on("open", function () {
    console.log('open');
    serialPort.on('data', function(data) {
        console.log('data received: ' + data);
    });
});

serialPort.on('error', function(err) {
    console.log('error: '+err);
});

serialPort.open();

If I ssh to yun and run the script I don't see any "dudee":

~/test# node serial.js
hello
open

While if I open the serial monitor I see it.

If I run the node script on my computer (changing the right serial port name) everything works nice and I see the dude..

What can it be?

1 Answer 1

2

Autosolved thanks to this old forum post.

It is Serial1 not Serial. In the Arduino code in the Yun Serial is a different object from Serial1. Even if it is not super well document (or at least not in the first dumb google search) here are some links that talks about Serial1:

https://www.arduino.cc/en/Tutorial/YunSerialTerminal http://andrea-toscano.com/arduino-yun-tcpip-to-serial1-redirect/ http://crossbar.io/iotcookbook/Arduino-Yun-Disable-Bridge/

3
  • Thanks man, this was really helpfull, as I had the same issue. Commented Oct 16, 2014 at 15:34
  • @nkint would you like to elaborate how did the post help you? Your answer would be good for other seekers. Commented Feb 25, 2016 at 5:29
  • @ChetanBhargava: it is only a different object in the arduino side.. Serial is different from Serial1 int he Yun..
    – nkint
    Commented Feb 25, 2016 at 9:19

Your Answer

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

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