Multiple software serial on Uno

Hello. I’m trying to make 2 softwareserial lines on a arduino pro mini (3.3v 8mhz)

I used esp and ser2 as SoftwareSerial vars.

This is what it should do:
→ Record send chars at ser2 OK
→ After saving send it to esp OK
→ Send message to esp OK
→ Receive esp message NOT WORKING :(.

I’m sure that the esp send a serial message on 9600. esp.available() is always false :(.

#include <SoftwareSerial.h>
SoftwareSerial esp(6, 7);      // RX, TX
SoftwareSerial ser2(10, 11);   // RX, TX

void setup() {
  esp.begin(9600);
  ser2.begin(9600);
  ser2.println("start");
}

void loop() {
  // Got esp message..
   if (esp.available()) {
      ser2.write("I m never here :(....");  // I'm never reaching this point
      char out[20];
      int count = 0;
      while(esp.available()) {
        out[count] = esp.read();
        count++;
      }
      for(int c = 0; c < count; c++) {
          ser2.write(out[c]);
      }
   }
   
   // Got ser2 message. Lets save it and send it..
   if (ser2.available()) {
     char out[20];
     int count = 0;
     while(ser2.available()) {
       out[count] = ser2.read();
       count++;
     }
     ser2.print(count);          // display count debug, tested OK!
     ser2.println();
     for(int c = 0; c < count; c++) {
         esp.write(out[c]);     // sending out the message, tested OK!
     }
  }
}

void espSend(String s) {
  Serial.println(s + "\r\n");
  // todo make bool? En return OK of niet OK..
}

Is the Arduino capable to run 2 SoftwareSerial?

And can I use this pin. Or is it a software problem?

SoftwareSerial can only pay attention to one serial port at a time. So if port1.availble() it will start looking for characters arriving from port1 but ignore port 2, then do port2.availble() it will start looking for characters arriving on port2 and ignore whatever arrives on port1.
Have you tested each port separately making sure they work one at a time.
If you need more port the Mega does 4 to my understanding.

1 Like

Thanks. For the response.

I'm trying to set a boolean after transmitting the ser2.

There is an example sketch you can try if you are interested. TwoPortReceive

It is working. Thanks for the example.

Its working sometimes, but a little bit buggy. I think I'm going to try AltSoftSerial

If that is not working perfect, I will stick to the real Serial.. But than my project wil not be as fancy as it could be :grin: