Arduino Library – AltSoftSerial

Installatie van Arduino IDE libraries: Arduino info
arduino logo rond
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

Download @ PJRC.com
Download @ Github (PaulStoffregen)

[#/arduino/libraries/altsoftserial” ]