| 1 |
/* |
| 2 |
Software serial multiple serial test |
| 3 |
|
| 4 |
Receives from the hardware serial, sends to software serial. |
| 5 |
Receives from software serial, sends to hardware serial. |
| 6 |
|
| 7 |
The circuit: |
| 8 |
* RX is digital pin 10 (connect to TX of other device) |
| 9 |
* TX is digital pin 11 (connect to RX of other device) |
| 10 |
|
| 11 |
Note: |
| 12 |
Not all pins on the Mega and Mega 2560 support change interrupts, |
| 13 |
so only the following can be used for RX: |
| 14 |
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 |
| 15 |
|
| 16 |
Not all pins on the Leonardo and Micro support change interrupts, |
| 17 |
so only the following can be used for RX: |
| 18 |
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). |
| 19 |
|
| 20 |
created back in the mists of time |
| 21 |
modified 25 May 2012 |
| 22 |
by Tom Igoe |
| 23 |
based on Mikal Hart's example |
| 24 |
|
| 25 |
This example code is in the public domain. |
| 26 |
|
| 27 |
*/ |
| 28 |
#include <SoftwareSerial.h> |
| 29 |
|
| 30 |
SoftwareSerial mySerial(10, 11); // RX, TX |
| 31 |
|
| 32 |
void setup() { |
| 33 |
// Open serial communications and wait for port to open: |
| 34 |
Serial.begin(57600); |
| 35 |
while (!Serial) { |
| 36 |
; // wait for serial port to connect. Needed for native USB port only |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
Serial.println("Goodnight moon!"); |
| 41 |
|
| 42 |
// set the data rate for the SoftwareSerial port |
| 43 |
mySerial.begin(4800); |
| 44 |
mySerial.println("Hello, world?"); |
| 45 |
} |
| 46 |
|
| 47 |
void loop() { // run over and over |
| 48 |
if (mySerial.available()) { |
| 49 |
Serial.write(mySerial.read()); |
| 50 |
} |
| 51 |
if (Serial.available()) { |
| 52 |
mySerial.write(Serial.read()); |
| 53 |
} |
| 54 |
} |