Interfacing Two Devices via SoftwareSerial

I’m not sure if I should have posted this in the Software Interfacing forum so apologies if it should have.

I am using the NewSoftSerial.h library to interface two devices to an Arduino Duemilanove. One is the Touchshield Slide and the other is an XBee Shield.

Here is the problem: I can send data out through the software serial from my Arduino to my Touchshield Slide, and likewise I can send data out to my XBee (I have tested this by writing data out to my LCD screen for the Touchshield and writing data to HyperTerminal for the Xbee.) However, I cannot receive data into my Arduino from either devices.

I tried writing from HyperTerminal to the host Arduino and I get nothing. The same is for my Touchscreen. If I remove one of the devices, the host Arduino and the remaining device can communicate back and forth no problem. But what I’m trying to go for is to get the two devices working together. For example:

Get data from XBee module into Arduino →
Arduino sends data to LCD →
LCD sends some data back to Arduino →
Arduino sends data out to XBee module.

I’ve attached the code for my host Arduino at the end. Is it a problem with my code, or is this a limitation of the hardware or software library?

#include <NewSoftSerial.h>

int rxPin = 3;
int txPin = 2;
int ledPin = 13;
char serialC;
char lcdC;
char xbeeC;

// Create NewSoftSerial for the LCD Touchscreen and XBee
NewSoftSerial lcdModule =  NewSoftSerial(rxPin, txPin);
NewSoftSerial xbeeModule =  NewSoftSerial(8, 9);

void setup()
{
  pinMode(ledPin, OUTPUT);  
  Serial.begin(9600);
  lcdModule.begin(9600);
  xbeeModule.begin(9600);
}

void loop()
{
  // If Serial is available, print out to LCD and Xbee
  if (Serial.available())
  {
    serialC = (char)Serial.read();
    lcdModule.print(serialC);
    xbeeModule.print(serialC);
  }
  
  // If something is coming from the XBee device,
  // read it in and print out to Serial
  if (xbeeModule.available())
  {
    xbeeC = (char)xbeeModule.read();
    Serial.print(xbeeC);
  }
  
  // If something is coming from the LCD Touchscreen,
  // read it in and print out to Serial. Also light an LED.
  if (lcdModule.available())
  {
    lcdC = (char)lcdModule.read();
    Serial.print(lcdC);
    
    if(lcdC == 'A')
    {
      digitalWrite(ledPin, HIGH);
    }
    if(lcdC == 'B')
    {
      digitalWrite(ledPin, LOW);
    }
  }
  
  delay(5);
}

During that delay(5) at the bottom of your loop, only the LCD data will be received by the NewSoftSerial since that is the only port that is active in newsoftserial. But the next line that executes (the "xbeemodele.available") discards anything received via lcd and immediately looks for data arriving via xbee. There's not much time for data to arrive there. Similarly, there is exactly no time between the activation of the xbee as the active serial device and the time you read it.

This will work, but badly:

loop { lcd.available(); // activate lcd serial delay(5) if (lcd.available()) { ... } xbee.available(); // activate xbee serial delay(5) if (xbee.available()) { ... } }

In this case, only data that arrives via the active device will be received (but data to the other device will be lost).

Basically, receiving data from 2 newsoftserial devices (where that data can arrive at random times) is not possible with NewSoftSerial.

Thanks tcharron, I realized that 2 NewSoftSerials would not work since it was a bottleneck at the hardware level.

I guess my next question would be, are the Arduino Megas capable of having two Software Serial devices?