0
votes

I'm using a raspberry pi (the first model) running on Jessy (8), node v0.12.6 and serialport 2.0.6. I have connected the pin Rx on the pin Tx of the physical serial port.

It's working fine with cat /dev/ttyAMA0 and echo "Hello" > /dev/ttyAMA0

The writing on the serial port with node-serialport is fine. I am using the code bellow (and using cat to read this) (source: https://www.npmjs.com/package/serialport)

var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var sp = new SerialPort("/dev/ttyAMA0", {
    baudrate:9600,
    databits: 8,
    parity: 'none',
    stopBits: 1,
    flowControl: false,
    parser: serialport.parsers.readline("\n"),
});

sp.on('open', function() {
    console.log("sending");
    sp.write("Hello");
});

I am now trying to read my serial port with node-serialport, but it doesn't work. When I am trying to read the serialport with node-serialport (and using echo to write on it), the data from echo are not writen in the terminal. The terminal only says "open". I am using this code, same source:

var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var sp = new SerialPort("/dev/ttyAMA0", {
    baudrate:9600,
    databits: 8,
    parity: 'none',
    stopBits: 1,
    flowControl: false,
    parser: serialport.parsers.readline("\n"),
});


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

I don't understand what's happening here. Any help would be much appreciated!

Thanks a lot! :)

Nicolas

1

1 Answers

1
votes

Problem solved, shell and kernel messages on the serial connection wasn't disabled with the raspi-config tool to prevent the kernel from using the serial port. (sudo raspi-config, Advanced-Options, Serial, No) Thanks to fivdi : https://github.com/voodootikigod/node-serialport/issues/715 Nicolas