Reading from Two ports with SoftwareSerial probelm

Hi,

I am trying to read data from RFID reader and send data using Bluetooth. When I am trying to do it separately, everything works fine, but when I am trying to combine 2 ports, I have problems. I tried to read in multiple forums for a while and it didn't help much. Here is my code:

#include <SoftwareSerial.h>


unsigned char TAG_1[38]={10,85,51,48,48,48,69,50,48,48,48,48,49,68,56,54,48,50,48,49,50,48,50,49,57,48,53,53,49,48,57,53,67,69,13,10,10};
unsigned char TAG_2[38]={10,85,51,48,48,48,51,48,48,56,51,51,66,50,68,68,68,57,48,49,52,48,48,48,48,48,48,48,48,48,51,57,66,66,13,10,10};
                      

SoftwareSerial RFIDSerial (8,9);
SoftwareSerial blueTooth (2,3);
unsigned char incomingByte;

void sendIdentifyCmd ()
{
  RFIDSerial.write (0x0A);    
  RFIDSerial.write (0x55);
  RFIDSerial.write (0x0D);
}

void copy_str(unsigned char *str_src, unsigned char *str_dest, int len){
  for(int i=0; i<len; i++){
    str_dest[i]=str_src[i];
  }
}

bool str_cmp(unsigned char *str1, unsigned char *str2, int len=37){
      for(int i=0; i<len; i++){
        if(str1[i]!=str2[i]){
          return false;
        }
      }
      return true;
}

void setup ()
{
  Serial.begin (9600);
  RFIDSerial.begin (38400);
  blueTooth.begin(38400);
  Serial.println ("begin initial Serial!\n");
 // blueTooth.println("lets bt\n");
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
}

void loop ()
{
  int i=0;
  unsigned char str[700]="";
  RFIDSerial.listen();
  if (RFIDSerial.isListening()) {  
    Serial.println("RFIDSerial is listening!"); //i am and getting this message
    }else{
      Serial.println("RFIDSerial is not listening!");
    }
  sendIdentifyCmd ();
  delay (2);
  
  while(RFIDSerial.available () > 0) //this loop is never reached because "he is available" is not printed
  {
    Serial.println("he is available");
    incomingByte=RFIDSerial.read();
    str[i]=incomingByte;

    Serial.print (str[i]);
    Serial.print (' ');
    i++;

  }
  unsigned char *temp_str=(unsigned char*)malloc((i+1)*sizeof(unsigned char));
  copy_str(str, temp_str, i);
  blueTooth.listen();
  blueTooth.println("hi");//i am and getting this message
  if(str_cmp(TAG_1, temp_str)){
  Serial.println();
  Serial.print("Hello Tag1\n");
  blueTooth.print("Hello Tag1 from bt");
  }
  if(str_cmp(TAG_2,temp_str)){
    Serial.println();
    Serial.print("Hello Tag2\n");
    blueTooth.print("Hello Tag2 from bt\n");
  }
  Serial.println();
  free(temp_str);
  delay (1000);
}

I put the method listen() in order to use different ports separately. As you can see, when I am trying to listen to RFID, I am getting the message that RFID is listening, and I even send the command to the reader to read tags. I can see on my module a blue led blinking which means that the reader is reading, but I am not able to read the data that comes from the reader. At the same time, I am sending data via the Bluetooth port when I am listening to it.

Now I am wondering who is the listen() method listens to.
So the questions are:

  1. Why RFIDSerial is not available and how to make it available?
  2. who is the listen() method listens to?

Thanks in advance!

It is just not practical to use two instances of SoftwareSerial. Only one of them can be active at any one time. If you need multiple serial ports you should use a Mega which has 3 spare HardwareSerial ports.

...R

i understand that Mega is easier to use in this case. But there must be a solution for Uno. I am managing to send data to the RFID, but not able to receive from it

Maybe that delay(2) isn't long enough. It's dodgy to rely on a fixed delay to solve Serial problems anyway, better to read until you have all the characters you expect, timing out when it's obvious they're not all coming.

As a short term test though, I'd substantially increase the delay until you get something from the RFID.

I cant believe that the solution was so simple. Thank you so much!!!!!