-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b612213
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains 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
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]); | ||
}); | ||
}); |
This file contains 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
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" | ||
} |
This file contains 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
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); | ||
} | ||
|
||
|
||
|