Skip to content

Instantly share code, notes, and snippets.

@prashanta
Created October 11, 2012 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashanta/3871893 to your computer and use it in GitHub Desktop.
Save prashanta/3871893 to your computer and use it in GitHub Desktop.
Data relay between two USARTs of an Arduino
#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