Created
October 11, 2012 12:05
-
-
Save prashanta/3871893 to your computer and use it in GitHub Desktop.
Data relay between two USARTs of an Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial = SoftwareSerial(10, 11);; // RX, TX | |
void setup() { | |
pinMode(10,INPUT); | |
pinMode(11,OUTPIT); | |
mySerial.begin(19200);// this connects to the other USART device | |
Serial.begin(19200); // this one connects to a computer via USB | |
while (!Serial) { | |
; // wait for serial port to connect. Needed for Leonardo only | |
} | |
} | |
void loop() { | |
if (mySerial.available() > 0) { | |
// relay everything received from mySerial to Serial | |
Serial.write(mySerial.read()); | |
} | |
if (Serial.available() > 0) { | |
// relay everything received from Serial to mySerial | |
mySerial.write(Serial.read()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment