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 cabled serial connection to another remote "server"-Arduino, which then actuates the relays.

According to the Arduino website, the SoftwareSerial Library has, amongst others, the following limitation: - "If using multiple software serial ports, only one can receive data at a time."

My plan is to poll constantly / on regular intervals both SoftwareSerial ports, e.g. by checking RFID_Serial.available() and XBeeSerial.available(), and if it turns out that data is available, to read it out and parse it accordingly. This obviouosly has to be done in an alternating fashion, i.e. one after the other. My questions are the following.

(1) Can I initialise the ports in void setup()

RFID_Serial.begin(..); XBeeSerial.begin(..);

... and are they then both actually active simultaneously (i.e. ready for commans like xxxxSerial.available(), or xxxxSerial.read(), or is in this case only the XBeeSerial active, because I it was the last one to be initialised?

(2) If I want to poll one after the other, do I have to "close" one SoftwareSerial port, e.g. by RFID_Serial.end(); and open the other (XbeeSerial.begin(..)) before I can do XBeeSerial.available() or read out by XBeeSerial.read()?

  • softwareSerial uses interrupts (rather than hardware) to acquire data. Because you cannot run two interrupts at the same time, 2 software serials' cannot receive both at the same time. I'm listing some options below. 1. Take a gamble. Hope they won't occure on the same time (bad idea) 2. Manage the flow. Make the other device not send data while one is sending. (Maybe impossible) 3. Check the priorities, make the XBee's priority vector lower as the RFID, and when you do not get a full/known RFID key, give feedback (with a light/buzzer) so the person will try his RFID key again. – Paul Apr 9 '15 at 14:26
  • You might want to use the XBEE with the hardware serial. And use the RFID on software serial. IF you're not receiving a lot from the master (since you only send the master which relays he has to actuate?) Why would you actually use two arduino's? The "slave" could, itself, actuate the relays? – Paul Apr 9 '15 at 14:28
  • @FuaZe: Thanks for your comments. Well, even if both, the RFID and the Xbee generate (the RFID)/receive (the Xbee) data at the same time, is it really a problem, because doesn't the data remain in the respective buffer until it gets read out during the next polling? – hobie Apr 9 '15 at 16:30
  • @Fuaze: There are several reasons why I use two arduinos. I have a limited number of available wires (3) between the slave and the master and I need a two-way communication. The master actuates three relays (door and two alarm systems), and needs to send the status to the slave, which, upon activation through the RFID tag, displays the status of the alarm system (on/off). The activation of the unit also activates three buttons to toggle the three relays. – hobie Apr 9 '15 at 16:37
  • The problem is that those buffers are filled by software, and your arduino can only do one software task at once (generally). So if two things send info to your arduino at the same time, there will be a problem. But you're explaining that the master sends the status after an RFID tag? So these van be two software serials as it's not on the same time? – Paul Apr 9 '15 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.