I'm having a bit of trouble with the Arduino 1.0.5 SoftwareSerial library. I understand that ideally, I should be using a Mega here, but unfortunately I need to make do with an Uno R3.
I understand that it is possible to use multiple SoftSerial ports, provided that you switch between the two using Soft1.listen();
etc. but I seem to be having troubles with this.
If I run the below sketch for example:
#include <SoftwareSerial.h>
SoftwareSerial Soft1(3,2);
SoftwareSerial Soft2(5,4);
void setup()
{
Soft2.begin(9600);
}
void loop()
{
Soft2.print("Test");
delay(1000);
}
I get exactly what I would expect - The word 'Test' printed every second. Now, if I replace Soft2.begin
with Soft1.begin
I get nothing. Adding Soft1.listen();
either before the 'print', or even before the 'begin' makes no difference. I need to read/write from one port, and write only to the second port, but it would appear that the SoftwareSerial library make up its mind on which port to use when they are declared rather during the program.
Has anybody ever used multiple SoftwareSerial ports successfully?
EDIT:
Just some more information for folks, if I swap the order of the software serial declarations, the live/dead ports reverse, so it really does appear to be something around that point. Just for testings sake, I've tried not starting either port until it is needed and doing the following:
void loop() {
Soft2.begin(9600);
Soft2.print("test2");
Soft2.end();
delay(1000); // For stability/to alleviate timing issues, whatever.
Soft1.begin(9600);
Soft1.print("test1");
Soft1.end();
}
But to no avail. I'm just seeing the 'test2' output.
Cheers,
Alex.