reference:
~ Arduino Uno
~ DisablingAutoResetOnSerialConnection
Node.js code, nodejsUno.js
//To install 'serialport' locally, enter the command:
//$ npm install serialport
//Otherwise, Error: Cannot find module 'serialport' will reported
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort('/dev/ttyACM0',
{ baudrate: 9600
});
serialPort.on("open", function () {
console.log('open');
setTimeout(function() {
serialPort.write("Hello...", function(err, results) {
console.log('err ' + err);
console.log('results ' + results);
});
setTimeout(function() {
serialPort.write("...from Node.js", function(err, results) {
console.log('err ' + err);
console.log('results ' + results);
});
}, 1000);
}, 3000);
});
Sketch on Arduino Uno, refer to the post "Read from Arduino Serial port, and write to 2x16 LCD".
No comments:
Post a Comment