| 1 |
/* |
| 2 |
Multiple 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 |
https://www.arduino.cc/en/Tutorial/BuiltInExamples/MultiSerialMega |
| 22 |
*/ |
| 23 |
|
| 24 |
|
| 25 |
void setup() { |
| 26 |
// initialize both serial ports: |
| 27 |
Serial.begin(9600); |
| 28 |
Serial1.begin(9600); |
| 29 |
} |
| 30 |
|
| 31 |
void loop() { |
| 32 |
// read from port 1, send to port 0: |
| 33 |
if (Serial1.available()) { |
| 34 |
int inByte = Serial1.read(); |
| 35 |
Serial.write(inByte); |
| 36 |
} |
| 37 |
|
| 38 |
// read from port 0, send to port 1: |
| 39 |
if (Serial.available()) { |
| 40 |
int inByte = Serial.read(); |
| 41 |
Serial1.write(inByte); |
| 42 |
} |
| 43 |
} |