source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

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