Created
December 9, 2017 03:20
-
-
Save koji/6195e1f13cfe535de978991b7d15290e to your computer and use it in GitHub Desktop.
nodejs send data to arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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