Linduino
1.3.0
Linear Technology Arduino-Compatible Demonstration Board
CN0416_SerialPassthrough.ino
Go to the documentation of this file.
1
/*
2
Modified from:
3
SerialPassthrough sketch
4
5
Added assertion of Enable signal to RS485 driver.
6
7
8
Some boards, like the Arduino 101, the MKR1000, Zero, or the Micro, have one
9
hardware serial port attached to Digital pins 0-1, and a separate USB serial
10
port attached to the IDE Serial Monitor. This means that the "serial
11
passthrough" which is possible with the Arduino UNO (commonly used to interact
12
with devices/shields that require configuration via serial AT commands) will
13
not work by default.
14
15
This sketch allows you to emulate the serial passthrough behaviour. Any text
16
you type in the IDE Serial monitor will be written out to the serial port on
17
Digital pins 0 and 1, and vice-versa.
18
19
On the 101, MKR1000, Zero, and Micro, "Serial" refers to the USB Serial port
20
attached to the Serial Monitor, and "Serial1" refers to the hardware serial
21
port attached to pins 0 and 1. This sketch will emulate Serial passthrough
22
using those two Serial ports on the boards mentioned above, but you can change
23
these names to connect any two serial ports on a board that has multiple ports.
24
25
created 23 May 2016
26
by Erik Nyquist
27
*/
28
29
void
setup
() {
30
pinMode(2, OUTPUT);
31
digitalWrite(2, LOW);
32
Serial.begin(9600);
33
Serial1.begin(9600);
34
}
35
36
void
loop
() {
37
if
(Serial.available()) {
// If anything comes in Serial (USB),
38
digitalWrite(2, HIGH);
39
delay(1);
40
Serial1.write(Serial.read());
// read it and send it out Serial1 (pins 0 & 1)
41
digitalWrite(2, LOW);
42
}
43
44
if
(Serial1.available()) {
// If anything comes in Serial1 (pins 0 & 1)
45
Serial.write(Serial1.read());
// read it and send it out Serial (USB)
46
}
47
}
setup
static void setup()
Definition:
CN0416_SerialPassthrough.ino:29
loop
static void loop()
Definition:
CN0416_SerialPassthrough.ino:36
LTSketchbook
Example Designs
CN0416_SerialPassthrough
CN0416_SerialPassthrough.ino
Generated on Thu Mar 19 2020 10:59:01 for Linduino by
1.8.13