| 1 |
/* |
| 2 |
SerialPassthrough sketch |
| 3 |
|
| 4 |
Some boards, like the Arduino 101, the MKR1000, Zero, or the Micro, have one |
| 5 |
hardware serial port attached to Digital pins 0-1, and a separate USB serial |
| 6 |
port attached to the IDE Serial Monitor. This means that the "serial |
| 7 |
passthrough" which is possible with the Arduino UNO (commonly used to interact |
| 8 |
with devices/shields that require configuration via serial AT commands) will |
| 9 |
not work by default. |
| 10 |
|
| 11 |
This sketch allows you to emulate the serial passthrough behaviour. Any text |
| 12 |
you type in the IDE Serial monitor will be written out to the serial port on |
| 13 |
Digital pins 0 and 1, and vice-versa. |
| 14 |
|
| 15 |
On the 101, MKR1000, Zero, and Micro, "Serial" refers to the USB Serial port |
| 16 |
attached to the Serial Monitor, and "Serial1" refers to the hardware serial |
| 17 |
port attached to pins 0 and 1. This sketch will emulate Serial passthrough |
| 18 |
using those two Serial ports on the boards mentioned above, but you can change |
| 19 |
these names to connect any two serial ports on a board that has multiple ports. |
| 20 |
|
| 21 |
created 23 May 2016 |
| 22 |
by Erik Nyquist |
| 23 |
|
| 24 |
https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialPassthrough |
| 25 |
*/ |
| 26 |
|
| 27 |
void setup() { |
| 28 |
Serial.begin(9600); |
| 29 |
Serial1.begin(9600); |
| 30 |
} |
| 31 |
|
| 32 |
void loop() { |
| 33 |
if (Serial.available()) { // If anything comes in Serial (USB), |
| 34 |
Serial1.write(Serial.read()); // read it and send it out Serial1 (pins 0 & 1) |
| 35 |
} |
| 36 |
|
| 37 |
if (Serial1.available()) { // If anything comes in Serial1 (pins 0 & 1) |
| 38 |
Serial.write(Serial1.read()); // read it and send it out Serial (USB) |
| 39 |
} |
| 40 |
} |