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

464 questions
21
votes
1 answer

How does serial communications work on the Arduino?

With reference to the Arduino Uno, Mega2560, Leonardo and similar boards: How does serial communications work? How fast is serial? How do I connect between a sender and receiver? Please note: This is intended as a reference question.
Nick Gammon
  • 38,901
  • 13
  • 69
  • 125
12
votes
6 answers

Send AT commands to ESP8266 from Arduino Uno via a SoftwareSerial port

GOAL From Arduino UNO, send AT commands to ESP8266 via a SoftwareSerial port and receive results. CURRENT STATUS I either send AT commands and get nothing back (wiring scheme 1) or I send AT commands and get garbage back (wiring scheme 2). Using the…
Paul
  • 223
  • 1
  • 2
  • 8
9
votes
4 answers

Is SoftwareSerial left out for the ATTiny85/84?

I want to use SoftwareSerial with my ATTiny85 and when I google it several projects claim that they are using it... I downloaded the hardware from https://code.google.com/p/arduino-tiny/, but when I try to add SoftwareSerial and compile I get: fatal…
Jason94
  • 303
  • 1
  • 5
  • 11
8
votes
3 answers

Serial Print, String And Variable On Same Line

How can I print to the serial monitor a string or just single character followed by a variable like "L 55"
Root0x
  • 205
  • 1
  • 3
  • 7
8
votes
2 answers

Get data from website with ESP8266 using AT commands

I'm trying to get data from a website by sending a HTTP GET request via AT commands for the ESP8266. Here is my current code: #include const byte rxPin = 2; const byte txPin = 3; SoftwareSerial ESP8266 (rxPin, txPin); void…
Henrik
  • 109
  • 1
  • 1
  • 5
6
votes
2 answers

Arduino Uno as USB to Serial converter (bypass 328p)

I'm trying out computer to computer serial communication using 2 Arduino Unos (both connected to different computers). Right now, I use the Software Serial library, which redirects data from the SoftwareSerial ports to the hardware Serial (over USB…
Carl
  • 99
  • 1
  • 3
6
votes
2 answers

Using SoftwareSerial for the serial monitor

Most programs follow this route: They have a Serial.begin() for the serial connection between PC and Arduino (the serial monitor) and they use SoftwareSerial for a device. Can you go the other way around? Can you use SoftwareSerial for the…
user1584421
  • 1,425
  • 3
  • 26
  • 36
6
votes
5 answers

Simultanous read and read/write on two serial connections

At the moment I'm using two softserials to connect to a GPS and an GSM module. It seems not possible to have two open software-serials. So I was looking for an solution After the initial-setup, the GPS module is only needed to be read from; while…
stUrb
  • 351
  • 2
  • 5
  • 10
5
votes
2 answers

How to read from and write to rs232 device from/to Arduino

I would like to read data from a rs232 device (SL-5868P Sound Level Meter). protocol and more : https://sigrok.org/wiki/Colead_SL-5868P. I already have a Python script to read the data with a TTL to USB converter (without Arduino). Now I also want…
Joost
  • 75
  • 1
  • 1
  • 6
5
votes
5 answers

AT command is not responding on serial monitor

I am trying to send AT commands to ESP8266. I re-flashed ESP8266 https://i.sstatic.net/z0hoc.jpg I followed this tutorial http://remotexy.com/en/help/esp8266-firmware-update/ and I hope it re-flashed successfully as there was no error. When I…
N Sharma
  • 355
  • 5
  • 9
  • 21
5
votes
3 answers

Make Sure \n is the last character in serial string

I have an Arduino that I've put between a computer and an RS485 device. The job of the Arduino now is just to transmit data but will eventually do data logging and have a small user interface as time goes by. So far, this serial read code has worked…
ATE-ENGE
  • 941
  • 3
  • 19
  • 32
5
votes
1 answer

HardwareSerial - check for overflow

The SoftwareSerial library has a built-in Overflow function, but the Serial library does not. Is there a simple way to check for a data buffer overflow on a hardware serial port?
Joel M.
  • 153
  • 5
5
votes
3 answers

esp8266 garbage out only when using SoftwareSerial

I'm trying to operate the esp8266. When I connect RX+TX pins to pins 1+2 on the Arduino, everything works fine. but when I'm trying to use software serial all hell breaks loose and the recieved data is garbadeged (It seems like everything is ok but…
Mercury
  • 101
  • 1
  • 5
4
votes
2 answers

Arduino unable to read 0x41 and 0x42 (reads others just fine (ICT bill acceptor)

Here is my issue: My code successfully recognizes and accepts $1 (0x40) and $20 bills (0x43), but it fails to recognize, display, process, anything for the $5 bill (0x41), and $10 bills (0x42). Also, when I say "Arduino", I mean TTGO btw... I have…
4
votes
1 answer

Non-blocking SoftwareSerial.Write

How to use SoftwareSerial.Write without blocking if buffer is full? Serial.write blocks if the buffer is full. So I need to check Serial.availableforwrite before calling write to prevent blocking. But there is no SoftwareSerial.availableforwrite.…
1
2 3
30 31