Multiple instances of NewSoftSerial and discarded data

Hi fellow Arduiners,

I got a first NewSoftSerial ser object, whose following code below tests availability of freshly arrived new data.

void loop()
{
	ser.available(); //To activate the device when you've several NewSoftSerial objects
	ser.flush();
	delay(500);
	if (ser.available()>0) Serial.println("Data arrived at most 500ms ago");
	else Serial.println("No Data arrived at most 500ms ago");
	delay(2000);
}

This works fine.

I’ve got a more complicated sketch with several NewSoftSerial objects. There, the above snippet put somewhere inside the code doesn’t work anymore: it nevers sees data. I tried to do a loop with 100 tests for availability, but it doesn’t help.

Does someone see from where the problem could come ?

I seem to recall reading here recently that NewSoftSerial doesn't support multiple instances.

Get a mega, it has four serial uart channels and all supported with the standard Serial.print library.

Lefty

I think you can have multiple instances but you can't use them at the same time.

Show us all the code, we can't see from that snippet what you are doing.


Rob

Thank you for your answers.

It does support multiple instances, see the dedicated paragraph on the official page: NewSoftSerial | Arduiniana. You simply can use only once at a time, which is what I do, as said Graynomad.

Unfortunately, the code is quite enormous and split between several files.

The relevant part is:

...
lcd.print("Hello"); //First NSS object

delay(4000);
	
ser.available(); //To activate the device when you've several NewSoftSerial objects
ser.flush();
delay(500);
if (ser.available()>0) Serial.println("Data arrived at most 500ms ago");
else Serial.println("No Data arrived at most 500ms ago"); //always returns that!
delay(2000);
...

It seems that I respect demands from NewSoftSerial to use multiple instances, doesn’t I ? The first available call is rightly to set the active object to ser.

I've got a more complicated sketch with several NewSoftSerial objects. There, the above snippet put somewhere inside the code doesn't work anymore: it nevers sees data. I tried to do a loop with 100 tests for availability, but it doesn't help.

Can you explain "doesn't work anymore" ? What does it do? What did you expect? Is the code reachable?

Can you minimize your code to a smaller sketch that still shows this behavior?

What are the datarates of the (how many) serial ports?

Many questions to get a better sight in this serial fog ;)