Created
July 10, 2015 09:39
-
-
Save jamesdavidson/4e088c352bdc5f30b982 to your computer and use it in GitHub Desktop.
Modified version of sample code from https://www.arduino.cc/en/Reference/SoftwareSerial
This file contains hidden or 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
/* | |
Software serial multple serial test | |
Receives from the hardware serial, sends to software serial. | |
Receives from software serial, sends to hardware serial. | |
The circuit: | |
* RX is digital pin 2 (connect to TX of other device) | |
* TX is digital pin 3 (connect to RX of other device) | |
created back in the mists of time | |
modified 25 May 2012 | |
by Tom Igoe | |
based on Mikal Hart's example | |
This example code is in the public domain. | |
*/ | |
#include <SoftwareSerial.h> | |
#define BAUD_RATE 9600 | |
char tmp; | |
SoftwareSerial mySerial(2, 3); // RX, TX | |
void setup() | |
{ | |
Serial.begin(BAUD_RATE); | |
mySerial.begin(BAUD_RATE); | |
} | |
void loop() | |
{ | |
if (mySerial.available()) { | |
tmp = mySerial.read(); | |
if (tmp == 13) { | |
Serial.write('\n'); | |
} | |
else { | |
Serial.write(tmp); | |
} | |
} | |
if (Serial.available()) { | |
tmp = Serial.read(); | |
mySerial.write(tmp); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment