Arduino Library – AltSoftSerial
Installatie van Arduino IDE libraries: Arduino info
Informatie (ENG):
AltSoftSerial emulates an additional serial port, allowing you to communicate with another serial device, and is particularly useful when simultaneous data flows are needed.
AltSoftSerial is capable of running up to 57600 baud on 16 MHz AVR with up to 9 µs interrupt latency from other libraries. Slower baud rates are recommended when other code may delay AltSoftSerial’s interrupt response by more than 9 µs.
Hardware Requirements
Board | Transmit Pin | Receive Pin | Unusable PWM |
---|---|---|---|
Teensy 3.0 & 3.1 | 21 | 20 | 22 |
Teensy 2.0 | 9 | 10 | (none) |
Teensy++ 2.0 | 25 | 4 | 26, 27 |
Arduino Uno | 9 | 8 | 10 |
Arduino Leonardo | 5 | 13 | (none) |
Arduino Mega | 46 | 48 | 44, 45 |
Wiring-S | 5 | 6 | 4 |
Sanguino | 13 | 14 | 12 |
The “Unusable PWM” pins can be used normally, with digitalRead() or digitalWrite(), but their PWM function controlled by analogWrite() will not work properly, because AltSoftSerial uses the timer which controls that pin’s PWM feature.
Basic Usage
AltSoftSerial mySerial;
- Create the AltSoftSerial object. Only one AltSoftSerial can be used, with the fixed pin assignments shown above.
mySerial.begin(baud);
- Initialize the port to communicate at a specific baud rate.
mySerial.print(anything);
- Print a number or text. This works the same as Serial.print().
mySerial.available();
- Returns the number of bytes received, which can be read.
mySerial.read();
- Reads the next byte from the port. If nothing has been received, -1 is returned.
Example program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <AltSoftSerial.h> AltSoftSerial altSerial; void setup() { Serial.begin(9600); Serial.println("AltSoftSerial Test Begin"); altSerial.begin(9600); altSerial.println("Hello World"); } void loop() { char c; if (Serial.available()) { c = Serial.read(); altSerial.print(c); } if (altSerial.available()) { c = altSerial.read(); Serial.print(c); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
v1.4 Fix issues with lower baud rates Support even slower baud rates Fix bugs with characters > 127 on some boards. v1.3 Bug fixes, should be very stable. v1.2.1 Same code as 1.2 release - update metadata to comply with new Arduino library specification requirements. v1.2b Same as version 1.2, with library.properties added. v1.2 Update comments |
Download @ PJRC.com
Download @ Github (PaulStoffregen)
[#/arduino/libraries/altsoftserial” ]