Skip to content

Commit 6a178b4

Browse files
agdlfacchinm
authored andcommitted
1 parent 996b3cd commit 6a178b4

File tree

6 files changed

+565
-0
lines changed

6 files changed

+565
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Software serial multple 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(9600);
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+
}
55+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
Software serial multple serial test
3+
4+
Receives from the two software serial ports,
5+
sends to the hardware serial port.
6+
7+
In order to listen on a software port, you call port.listen().
8+
When using two software serial ports, you have to switch ports
9+
by listen()ing on each one in turn. Pick a logical time to switch
10+
ports, like the end of an expected transmission, or when the
11+
buffer is empty. This example switches ports when there is nothing
12+
more to read from a port
13+
14+
The circuit:
15+
Two devices which communicate serially are needed.
16+
* First serial device's TX attached to digital pin 10(RX), RX to pin 11(TX)
17+
* Second serial device's TX attached to digital pin 8(RX), RX to pin 9(TX)
18+
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+
28+
created 18 Apr. 2011
29+
modified 19 March 2016
30+
by Tom Igoe
31+
based on Mikal Hart's twoPortRXExample
32+
33+
This example code is in the public domain.
34+
35+
*/
36+
37+
#include <SoftwareSerial.h>
38+
// software serial #1: RX = digital pin 10, TX = digital pin 11
39+
SoftwareSerial portOne(10, 11);
40+
41+
// software serial #2: RX = digital pin 8, TX = digital pin 9
42+
SoftwareSerial portTwo(8, 9);
43+
44+
void setup() {
45+
// Open serial communications and wait for port to open:
46+
Serial.begin(9600);
47+
while (!Serial) {
48+
; // wait for serial port to connect. Needed for native USB port only
49+
}
50+
51+
52+
// Start each software serial port
53+
portOne.begin(9600);
54+
portTwo.begin(9600);
55+
}
56+
57+
void loop() {
58+
// By default, the last intialized port is listening.
59+
// when you want to listen on a port, explicitly select it:
60+
portOne.listen();
61+
Serial.println("Data from port one:");
62+
// while there is data coming in, read it
63+
// and send to the hardware serial port:
64+
while (portOne.available() > 0) {
65+
char inByte = portOne.read();
66+
Serial.write(inByte);
67+
}
68+
69+
// blank line to separate data from the two ports:
70+
Serial.println();
71+
72+
// Now listen on the second port
73+
portTwo.listen();
74+
// while there is data coming in, read it
75+
// and send to the hardware serial port:
76+
Serial.println("Data from port two:");
77+
while (portTwo.available() > 0) {
78+
char inByte = portTwo.read();
79+
Serial.write(inByte);
80+
}
81+
82+
// blank line to separate data from the two ports:
83+
Serial.println();
84+
}
85+
86+
87+
88+

libraries/SoftwareSerial/keywords.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#######################################
2+
# Syntax Coloring Map for SoftwareSerial
3+
# (formerly NewSoftSerial)
4+
#######################################
5+
6+
#######################################
7+
# Datatypes (KEYWORD1)
8+
#######################################
9+
10+
SoftwareSerial KEYWORD1
11+
12+
#######################################
13+
# Methods and Functions (KEYWORD2)
14+
#######################################
15+
16+
begin KEYWORD2
17+
end KEYWORD2
18+
read KEYWORD2
19+
write KEYWORD2
20+
available KEYWORD2
21+
isListening KEYWORD2
22+
stopListening KEYWORD2
23+
overflow KEYWORD2
24+
flush KEYWORD2
25+
listen KEYWORD2
26+
peek KEYWORD2
27+
28+
#######################################
29+
# Constants (LITERAL1)
30+
#######################################
31+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=SoftwareSerial
2+
version=1.0
3+
author=Arduino
4+
maintainer=Arduino <info@arduino.cc>
5+
sentence=Enables serial communication on any digital pin.
6+
paragraph=The SoftwareSerial library has been developed to allow serial communication on any digital pin of the board, using software to replicate the functionality of the hardware UART. It is possible to have multiple software serial ports with speeds up to 115200 bps.
7+
category=Communication
8+
url=http://www.arduino.cc/en/Reference/SoftwareSerial
9+
architectures=samd
10+

0 commit comments

Comments
 (0)