Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DanialK committed Apr 12, 2014
0 parents commit b612213
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var SerialPort = require("serialport").SerialPort;
var serialport = new SerialPort("/dev/tty.usbmodem1421");
serialport.on('open', function(){
console.log('Serial Port Opend');
serialport.on('data', function(data){
console.log(data[0]);
});
});
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Arduino Nodejs Serial Port Communication",
"version": "0.0.0",
"description": "Connecting Arduino to Nodejs using serial ports",
"main": "app.js",
"dependencies": {
"serialport": "^1.3.1"
},
"author": "Danial Khosravi",
"license": "ISC"
}
35 changes: 35 additions & 0 deletions serialport.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Writing to Serial Port
Writes a digital input on pin 2 into the serial
This example code is in the public domain.
*/

// digital pin 2 has a pushbutton attached to it.
int pushButton = 2;

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button into the serial port:
if(buttonState == HIGH){
Serial.write(1);
}else{
Serial.write(0);
}

// delay in between reads for stability
delay(1);
}



0 comments on commit b612213

Please sign in to comment.