Skip to content

Commit a24999d

Browse files
committed
Updated SoftwareSerial examples so that they work easier with Leonardo and Mega
1 parent 6e8e13d commit a24999d

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

Diff for: libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino

+17-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55
Receives from software serial, sends to hardware serial.
66
77
The circuit:
8-
* RX is digital pin 2 (connect to TX of other device)
9-
* TX is digital pin 3 (connect to RX of other device)
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 support change interrupts,
17+
so only the following can be used for RX:
18+
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
1019
1120
created back in the mists of time
12-
modified 9 Apr 2012
21+
modified 25 May 2012
1322
by Tom Igoe
1423
based on Mikal Hart's example
1524
@@ -18,17 +27,17 @@
1827
*/
1928
#include <SoftwareSerial.h>
2029

21-
SoftwareSerial mySerial(2, 3); // RX, TX
30+
SoftwareSerial mySerial(10, 11); // RX, TX
2231

2332
void setup()
2433
{
25-
// Open serial communications and wait for port to open:
34+
// Open serial communications and wait for port to open:
2635
Serial.begin(57600);
27-
while (!Serial) {
36+
while (!Serial) {
2837
; // wait for serial port to connect. Needed for Leonardo only
2938
}
3039

31-
40+
3241
Serial.println("Goodnight moon!");
3342

3443
// set the data rate for the SoftwareSerial port
@@ -43,3 +52,4 @@ void loop() // run over and over
4352
if (Serial.available())
4453
mySerial.write(Serial.read());
4554
}
55+

Diff for: libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino

+15-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@
1616
* First serial device's TX attached to digital pin 2, RX to pin 3
1717
* Second serial device's TX attached to digital pin 4, RX to pin 5
1818
19+
Note:
20+
Not all pins on the Mega and Mega 2560 support change interrupts,
21+
so only the following can be used for RX:
22+
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
23+
24+
Not all pins on the Leonardo support change interrupts,
25+
so only the following can be used for RX:
26+
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
27+
1928
created 18 Apr. 2011
20-
modified 9 Apr 2012
29+
modified 25 May 2012
2130
by Tom Igoe
2231
based on Mikal Hart's twoPortRXExample
2332
@@ -26,11 +35,12 @@
2635
*/
2736

2837
#include <SoftwareSerial.h>
29-
// software serial #1: TX = digital pin 2, RX = digital pin 3
30-
SoftwareSerial portOne(2, 3);
38+
// software serial #1: TX = digital pin 10, RX = digital pin 11
39+
SoftwareSerial portOne(10,11);
3140

32-
// software serial #2: TX = digital pin 4, RX = digital pin 5
33-
SoftwareSerial portTwo(4, 5);
41+
// software serial #2: TX = digital pin 8, RX = digital pin 9
42+
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
43+
SoftwareSerial portTwo(8,9);
3444

3545
void setup()
3646
{

0 commit comments

Comments
 (0)