Skip to content

Commit 789d865

Browse files
agdllmihalkovic
authored andcommitted
Modified example to not generate confusion
Only Arduino Mega was mentioned, but actually many boards have more than one Serial port
1 parent 4d9cf49 commit 789d865

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Multple Serial test
3+
4+
Receives from the main serial port, sends to the others.
5+
Receives from serial port 1, sends to the main serial (Serial 0).
6+
7+
This example works only with boards with more than one serial like Arduino Mega, Due, Zero etc
8+
9+
The circuit:
10+
* Any serial device attached to Serial port 1
11+
* Serial monitor open on Serial port 0:
12+
13+
created 30 Dec. 2008
14+
modified 20 May 2012
15+
by Tom Igoe & Jed Roach
16+
modified 27 Nov 2015
17+
by Arturo Guadalupi
18+
19+
This example code is in the public domain.
20+
21+
*/
22+
23+
24+
void setup() {
25+
// initialize both serial ports:
26+
Serial.begin(9600);
27+
Serial1.begin(9600);
28+
}
29+
30+
void loop() {
31+
// read from port 1, send to port 0:
32+
if (Serial1.available()) {
33+
int inByte = Serial1.read();
34+
Serial.write(inByte);
35+
}
36+
37+
// read from port 0, send to port 1:
38+
if (Serial.available()) {
39+
int inByte = Serial.read();
40+
Serial1.write(inByte);
41+
}
42+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use two of the serial ports available on the Arduino board.

0 commit comments

Comments
 (0)