1

Hi we are using an Arduino Micro and working with a Bluetooth device and a Rfid Scanner from Sparkfun(ID-20 LA). For that we implemented 2 SoftwareSerial objects and the Serial port for the Serial Monitor. If we use one SoftwareSerial object and the normal Serial everything works fine. For example we can send and receive things over Bluetooth. But when adding another SoftwareSerial object( Rfid then ) One of them doesn't work.

Starting with the Rfid SoftwareSerial ends up to the same result.

We've also already tried to change the ports and so one.

Every help is appreciated. Thanks in advance.

The Code ( this is already the third programm nothing has changed )

#include <SoftwareSerial.h>

SoftwareSerial rf(11, 12);
SoftwareSerial bt(8,9);

void setup() {
  Serial.begin(9600);
  rf.begin(9600);
  bt.begin(9600);

}

void loop() {
  if(Serial.available())
  {
   while(Serial.available())
     Serial.write(Serial.read());

   Serial.println(""); 
  }

  if(rf.available())
  {
   while(rf.available())
     Serial.write(rf.read());

   Serial.println(""); 
  }

  if(bt.available())
  {
   while(bt.available())
     Serial.write(bt.read());

   Serial.println(""); 
  }
}
1

2 Answers 2

3

Taken from http://www.arduino.cc/en/Reference/SoftwareSerial:

Limitations

The library has the following known limitations:

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

If your project requires simultaneous data flows, see Paul Stoffregen's AltSoftSerial library. AltSoftSerial overcomes a number of other issues with the core SoftwareSerial, but has it's own limitations. Refer to the AltSoftSerial site for more information.

If you look at SoftwareSerial's code, you'll understand the limitation:

/* static */
inline void SoftwareSerial::handle_interrupt()
{
  if (active_object)
  {
    active_object->recv();
  }
}

Basically, the code waits for an interrupt to detect state changes on the pin, and directs it to the "active" serial object.

Hope this helps.

0

Under the known limitations in the SoftwareSerial documentation:

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

It's still possible to use multiple instances of SoftwareSerial. However, when you want to use a specific one, you need to call the listen() member function. This will allow it to receive data until you call that function on a different instance.

One very important thing to understand is that data is not queued in the background. If information arrives while a SoftwareSerial port is not listening, it simply gets discarded.

There may be alternative software serial libraries which suit your needs, depending on how they use interrupts. Alternatively, you could use a different Arduino which has multiple hardware serial ports (such as the Mega).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.