Questions tagged [softwareserial]

A library for emulating UART functionality in software on any available digital IO pins. Use this tag for questions regarding SoftwareSerial.

Introduction

SoftwareSerial uses interrupts and carefully timed sequences to provide aynsc serial communications on ports other than those supported by the hardware serial (HardwareSerial class).

You should not use SoftwareSerial if HardwareSerial is available on the same pins. Hardware serial is more robust, and can send and receive in the background. SoftwareSerial cannot.


Supported pins

On the Atmega328P-based Arduinos (eg. Uno, Pro, Nano, Mini) you can use SoftwareSerial on any pins.

On the Mega2560 you can only use it for receiving on pins 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).

On the Leonardo and Micro you can only use it for receiving on pins 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

This is because SoftwareSerial requires pin-change interrupts to detect receiving a new byte, and pin-change interrupts are only supported on the pins mentioned above. You do not need pin-change interrupts to transmit, so you can choose any pin for transmitting.


Limitations

  • For timing reasons, SoftwareSerial disables interrupts once a byte has started to be received (until it has been completely received). It also disables interrupts whilst sending.

    Thus you cannot both send, and receive, at the same time, using SoftwareSerial.

  • SoftwareSerial only deals with 8-bit bytes. HardwareSerial can read and write from 5 to 9 bits.

  • SoftwareSerial only reads/writes with no parity and one stop bit. HardwareSerial can write with none/even/odd parity, and use one or two stop bits.

  • Because interrupts are turned off during sending and receiving you cannot do as much background processing whilst sending/receiving.


Enhancements

  • SoftwareSerial has an "inverted logic" mode on the constructor, which lets you read/write with the normal logic inverted. That is, +5V is a 0-bit, and 0V is a 1-bit.

Usefulness

It is handy to use SoftwareSerial where you need to access multiple serial devices, such as a GPS and a printer at the same time.


Alternatives

  • On the Mega2560 you have four hardware serial ports, so you can use those instead of SoftwareSerial.

  • There is another library: AltSoftSerial Library. This removes some of the above limitations, and adds some of its own.


Reference

460 questions
2
votes
0 answers

Multiple SoftwareSerial ports - how to handle the limitations

I am building an access control project which uses two SoftwareSerial ports. One will be used for communication with an RFID reader and another one to receive serial messages via an Xbee (e.g. remote commands). The hardware serial port is used for a…
hobie
  • 487
  • 1
  • 5
  • 12
1
vote
1 answer

Accessing softwareserial.available in the arduino loop function always return 0 but in the setup function returns the available byte

I am working on an accident detection system using arduino, what i want to do is to store the recipient phonenumber received as an SMS in the arduino EEPROM, using Serial1.available() to check for bytes in the software serial within the loop()…
1
vote
0 answers

Serial port - ESP8288 (TCP/IP) - WiFi - "Virtual serial port on my linux/windows PC" [Solved]

Is there an way to transport a serial port via TCP/IP to a PC. The goal is to have a ESP8266 dongle that I connect to a router, switch or other device with a serial port for configuring. I have found RFC 2217 that is suitable for the goal. Is there…
MatsK
  • 1,356
  • 1
  • 11
  • 24
1
vote
1 answer

How to send data from arduino to Temp Controller for setting temp?

I send data from arduino by method following. Configure the value : byte message[ ]; #include #define RX 2 #define TX 3 int incomingByte = 0; SoftwareSerial mySerial(RX, TX); void setup() { pinMode(5, OUTPUT); …
TW_JM
  • 11
  • 2
1
vote
1 answer

SoftwareSerial error:

Please help me with this library "Softwareserial". The basic sketch does not work. Please look the errors: C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:128:2: error: #error This version of SoftwareSerial supports…
user23441
  • 13
  • 3
1
vote
0 answers

Trying to pass a single char to a serial device

Good day, I have a serial device that when connected via hyper terminal gives me a status report when I press the letter 'd' no enter key or anything required just the letter d. Also Ctrl-t will give me some routing information. I would like to…
Tony M
  • 31
  • 6
1
vote
2 answers

Trying to pass a char to software serial with a button press

Good day everyone, I'm returning to the Arduino world after my a 3 year hiatus following the birth of my son. I'm trying to push a button connected to pin 2 and have that send a 'd' to SoftwareSerial on pins 10,11. This should trigger an output back…
Tony M
  • 31
  • 6
0
votes
1 answer

serial 1 was not declared in the scope

#include LiquidCrystal lcd(2, 3, 4, 5, 6, 7); #include char Mob[20]="+923319020922"; String stringGPS = ""; String stringGPS1 = ""; char c=0; int t=0,i; int buzzer = 9; int buttonState = 0; SoftwareSerial…
0
votes
1 answer

Help understanding SoftwareSerial recv() and PCINT

In the SoftwareSerial library, I see the beginning of recv() as follows void SoftwareSerial::recv() { #if GCC_VERSION < 40302 // Work-around for avr-gcc 4.3.0 OSX version bug // Preserve the registers that the compiler misses // (courtesy of…
chugadie
  • 101
  • 1
0
votes
2 answers

SoftwareSerial library

How do I rectify this error? Clearly it says there is some error in the library, so how do I correct it? C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:1: error: expected unqualified-id before 'if'
yash jain
  • 1
  • 2
0
votes
2 answers

How do I get the Itead 3G shield to work?

I've tried a pretty standard code but the Serial Monitor yields zero response. Using a standard Arduino Uno (tried a second one as well, just to be sure) and am now trying the second shield with this code: #include SoftwareSerial…
user15836
  • 1
  • 1
0
votes
2 answers

Need Basic Help with Software Serial

I am testing the basic Software Serial example on the arduino website, but I cant get the myserial to print #include SoftwareSerial mySerial(10, 11); // RX, TX void setup() { // Open serial communications and wait for port to…
Umbus
  • 143
  • 6
0
votes
1 answer

How can I see the mySerial.print( ) through the serialmonitor on IDE?

I made an object named "mySerial" like this. SoftwareSerial mySerial(2,3) //pin 2 = RX, pin 3 = TX also I made pin 13 periodically(0.5 seconds) blink(HIGH/LOW), then the signal from pin 13 goes directly to pin 2 and pin 0(basic RX pin of UNO). I…
user14937
  • 1
  • 1
0
votes
1 answer

cannot read from softwareserial

I am able to use AT command from the Serial monitor however when I run the following code nothing is sent or received from the ESP8266. Can someone advise what could be the problem. #include ; SoftwareSerial esp8266(0,1); // make…