Skip to content

Instantly share code, notes, and snippets.

@koji
Created December 9, 2017 03:20
Show Gist options
  • Save koji/6195e1f13cfe535de978991b7d15290e to your computer and use it in GitHub Desktop.
Save koji/6195e1f13cfe535de978991b7d15290e to your computer and use it in GitHub Desktop.
nodejs send data to arduino
const SerialPort = require('serialport');
const port = new SerialPort('/dev/cu.usbmodem****', {
parser: SerialPort.parsers.readline('\n'),
baudrate: 9600
})
port.on('open', function () {
console.log('Serial open.');
})
port.on('data', function (data) {
console.log('Data: ' + data)
// send rgb data
write(data)
})
function write(data) {
console.log('Write: ' + data);
port.write(new Buffer(data), function(err, results) {
if(err) {
console.log('Err: ' + err)
console.log('Results: ' + results)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment