Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone Arduino Test #600

Closed
wants to merge 9 commits into from
Closed
11 changes: 3 additions & 8 deletions arduinoTest/arduinoEcho/arduinoEcho.ino
@@ -1,18 +1,13 @@
const int ledPin = 11;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Serial.write("READY");
}

void loop() {

while (Serial.available()) {
digitalWrite(ledPin, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
Serial.write(Serial.read());
}

delay(100);
digitalWrite(ledPin, LOW);
digitalWrite(LED_BUILTIN, LOW);
}
51 changes: 51 additions & 0 deletions arduinoTest/serialDuplexTest.js
@@ -0,0 +1,51 @@
/*
serialDuplexTest.js

Tests the functtionality of the serial port library.
To be used in conjunction with the Arduino sketch called ArduinoEcho.ino
*/
'use strict';

// serial port initialization:
var serialport = require('../serialport'); // include the serialport library
var SerialPort = serialport.SerialPort; // make a local instance of serial
var portName = process.argv[2]; // get the port name from the command line
var myPort = new SerialPort(portName); // open the serial port:
var output = 32; // ASCII space; lowest printable character
var byteCount = 0; // number of bytes read

function openPort() {
console.log('port open');
console.log('baud rate: ' + myPort.options.baudRate);
var outString = String.fromCharCode(output);
console.log('String is: ' + outString);
myPort.write(outString);
}

function receiveData(data) {
if (output <= 126) { // highest printable character: ASCII ~
output++;
} else {
output = 32; // lowest printable character: space
}
console.log('received: ' + data);
console.log('Byte count: ' + byteCount);
byteCount++;
var outString = String.fromCharCode(output);
myPort.write(outString);
console.log('Sent: ' + outString);
}

function closePort() {
console.log('port closed');
}

function serialError(error) {
console.log('there was an error with the serial port: ' + error);
myPort.close();
}

myPort.on('open', openPort); // called when the serial port opens
myPort.on('data', receiveData); // called when data comes in
myPort.on('close', closePort); // called when the serial port closes
myPort.on('error', serialError); // called when there's an error with the serial port