Skip to content

Commit 8eca336

Browse files
committed
Renamed ino file
2 parents 01c3a7b + 0f4a10f commit 8eca336

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ ls /dev/{tty,cu}.*
5353
On a PC you can use the command line and the following command:
5454

5555
```
56+
chgport
57+
```
58+
59+
On my PC when I use the `chgport` command I get the following output:
5660

5761
```
62+
AUX = \DosDevices\COM1
63+
COM1 = \Device\Serial0
64+
COM3 = \Device\Serial2
65+
```
66+
67+
In my Node.js I would use just `COM3` as my serialport string.
68+
69+
If you're not sure which one is your Arduino, just disconnet your Arduino and execute the cpommand again and take note of which port is no longer on the list.
5870

5971
Or you can find the name in [Arduino Create](https://create.arduino.cc/editor) in the drop down menu used to select your Arduino.
6072

@@ -154,16 +166,17 @@ You will need to setup the following circuit using your Arduino:
154166

155167
## Launch Application
156168

157-
1. Using the Terminal start your Node.js app using `node app.js`.
158-
2. Open up a browser and enter the URL `http://localhost:3000/`.
159-
3. Using [Arduino Create](https://create.arduino.cc/editor) upload the sketch to your Arduino.
169+
1. Using [Arduino Create](https://create.arduino.cc/editor) upload the sketch to your Arduino.
170+
2. Using the Terminal start your Node.js app using `node app.js`.
171+
3. Open up a browser and enter the URL `http://localhost:3000/`.
160172
4. Using your browser push the on and off buttons and watch your Arduino for a changing light.
161173

162174
## Tutorial Requirements:
163175

164176
* [Visual Studio Code](https://code.visualstudio.com/) or [Brackets](http://brackets.io/) (or any code editor)
165-
* [Filezilla](https://filezilla-project.org/) (or any FTP program)
166177
* [Arduino Create](https://create.arduino.cc/editor)
178+
* [SerialPort NPM](https://www.npmjs.com/package/serialport)
179+
* [Socket.io](https://socket.io/)
167180

168181
Full tutorial URL: https://codeadam.ca/learning/arduino-from-nodejs.html
169182

node-to-arduino.ino

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
*/
3+
4+
int lightPin = 2;
5+
6+
void setup()
7+
{
8+
9+
pinMode(lightPin, OUTPUT);
10+
Serial.begin(9600);
11+
12+
}
13+
14+
void loop() {
15+
16+
if (Serial.available() > 0) {
17+
18+
String receivedString = "";
19+
20+
while (Serial.available() > 0) {
21+
receivedString += char(Serial.read ());
22+
}
23+
24+
Serial.println(receivedString);
25+
26+
if(receivedString == "1")
27+
digitalWrite(lightPin,HIGH);
28+
else
29+
digitalWrite(lightPin,LOW);
30+
31+
}
32+
33+
}

node_to_arduino.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* * This file receives a Serial value of "1" or "0" and changes the light based on * that value. */ // Define the port for the LEDint lightPin = 2; void setup() { // Initialize the light pin pinMode(lightPin, OUTPUT); // Initialize the Serial Serial.begin(9600); }void loop() { // CHeck to see if Serial data is being received if (Serial.available() > 0) { // Create a new string variable to receive Serial data String receivedString = ""; // Loop through received data and append to the receivedString variable while (Serial.available() > 0) { receivedString += char(Serial.read ()); } // Print received Serial data Serial.println(receivedString); // Change LED status based on received data if(receivedString == "1") digitalWrite(lightPin,HIGH); else digitalWrite(lightPin,LOW); }}

0 commit comments

Comments
 (0)