loading

The Arduino hardware has built-in support for serial communication on pins 0 and 1 (which also goes to the computer via the USB connection).The native serial support happens via a piece of hardware (built into the chip) called a UART. This hardware allows the Atmega chip to receive serial communication even while working on other tasks, as long as there room in the 64 byte serial buffer.For normal serial communication you do not need to add any extra library in Arduino IDE.Such as,

void setup() {
Serial.begin(9600); // initialize serial communication at 9600 bits per second

}

void loop() {

Serial.println("Hello Everyone");
delay(1000);

}

Since pin 0 and pin 1 is internally connected.So when we upload this program in arduino and open serial monitor.This will print "Hello Everyone".If we use any communication device to do serial communication that will send "Hello Everyone" string in other device using serial communication.Now, if you need to add more serial communication port to do serial communication.Then you need to add a library which is called "SoftwareSerial.h".

Step 1: About SoftwareSerial Library

The SoftwareSerial library has been developed to allow serial communication on other digital pins of the Arduino, using software to replicate the functionality (hence the name "SoftwareSerial"). It is possible to have multiple software serial ports with speeds up to 115200 bps. A parameter enables inverted signaling for devices which require that protocol.

The version of SoftwareSerial included in 1.0 and later is based on the NewSoftSerial library developed by Mikal Hart.SoftwareSerial and NewSoftSerial library working principle is same. NewSoftSerial library is old version of SoftwareSerial library.

There are some limitation in SoftwareSerial library.

The library has the following known limitations:

If using multiple software serial ports, only one can receive data at a time.

Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

Not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

Example:

Step 2: Overcome SoftwareSerial Library Limitation

Main limitation :

When we will use SoftwareSerial Library for multiple serial ports, only one can receive data at a time.So this can create a problem, when we need to receive data at a time from multiple serial ports.

Process of overcome the limitaion : AltSoftSerial Library allowing you to communicate simultaneously.AltSoftSerial 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.

Link: http://www.pjrc.com/teensy/td_libs_AltSoftSerial.h...

About This Instructable

648views

2favorites

License:

More by Abdullah_Al_Mamun_EEE_EWU_Bangladesh:Serial communication process in Arduino  Create Internal Interrupt In Arduino How to Simulate Arduino in Proteus 
Add instructable to: