Arduino Mega RFID

Hi,

I already done two RFID reader(ID-20) with UNO. But now, I want use two RFID reader with MEGA. I set up the Serial1 and 2. But it doesn’t works.

UNO code:

#include <SoftwareSerial.h>
SoftwareSerial SSerial(11,10);

int RFIDResetPin1 = 3; //digital3
int RFIDResetPin2 = 4; //digital4
char tagString1[13];
char tagString2[13];
boolean gotOne = false;

void setup(){
    Serial.begin(9600);
    SSerial.begin(9600);

    pinMode(RFIDResetPin1, OUTPUT);
    pinMode(RFIDResetPin2, OUTPUT);

    digitalWrite(RFIDResetPin1, HIGH);
    digitalWrite(RFIDResetPin2, HIGH);
}

void loop(){

    checkRFIDReader1();// check serial
    checkRFIDReader2();// check sserial

}


void checkRFIDReader1(){

    if(Serial.available() >= 14){

        int readByte = Serial.read();

        if(readByte != 2)
            return;

        clearTag1();            // clearTag1 before reading in new data
        Serial.readBytesUntil(3, tagString1, 13);

        Serial.print("From reader 1 : ");
        Serial.println(tagString1);

        if (!gotOne)
            gotOne = true;

        if (tagEqual() && gotOne){
            Serial.println("Item out !");
            gotOne = false;
            clearTag1();
            clearTag2();
        }

        resetReader1(); //eset the RFID reader
    }

}

void checkRFIDReader2(){

    if(SSerial.available() >= 14){

        int readByte = SSerial.read();

        if(readByte != 2)
            return;

        clearTag2();
        SSerial.readBytesUntil(3, tagString2, 13);

        Serial.print("From reader 2 : ");
        Serial.println(tagString2);

        if (!gotOne)
            gotOne = true;

        if (tagEqual() && gotOne){
            Serial.println("Item in !");
            clearTag1();
            clearTag2();
        }

        resetReader2(); //eset the RFID reader
    }

}



void clearTag1(){

    for(int i = 0; i < 13; i++)
        tagString1[i] = 0;
}

void clearTag2(){

    for(int i = 0; i < 13; i++)
        tagString2[i] = 0;
}

boolean emptyTag1(){
    for (int i=0; i<13; i++)
        if (tagString1[i] != 0)
            return false;
    return true;
}

boolean emptyTag2(){
    for (int i=0; i<13; i++)
        if (tagString2[i] != 0)
            return false;
    return true;
}

boolean tagEqual(){

    if(emptyTag1() || emptyTag2())
        return false;

    for(int i = 0; i < 13; i++)
        if(tagString1[i] != tagString2[i])
            return false;

    return true;
}

void resetReader1(){
  ///////////////////////////////////
  //Reset the RFID reader to read again.
  ///////////////////////////////////
  digitalWrite(RFIDResetPin1, LOW);
  digitalWrite(RFIDResetPin1, HIGH);
  delay(150);
}

void resetReader2(){
  ///////////////////////////////////
  //Reset the RFID reader to read again.
  ///////////////////////////////////
  digitalWrite(RFIDResetPin2, LOW);
  digitalWrite(RFIDResetPin2, HIGH);
  delay(150);
}

Mega code

int RFIDResetPin1 = 3; //digital3
int RFIDResetPin2 = 4; //digital4
char tagString1[13];
char tagString2[13];
boolean gotOne = false;

void setup(){
    Serial1.begin(9600);
    Serial2.begin(9600);

    pinMode(RFIDResetPin1, OUTPUT);
    pinMode(RFIDResetPin2, OUTPUT);

    digitalWrite(RFIDResetPin1, HIGH);
    digitalWrite(RFIDResetPin2, HIGH);
}

void loop(){

    checkRFIDReader1();// check serial
    checkRFIDReader2();// check sserial

}


void checkRFIDReader1(){

    if(Serial1.available() >= 14){

        int readByte = Serial1.read();

        if(readByte != 2)
            return;

        clearTag1();            // clearTag1 before reading in new data
        Serial1.readBytesUntil(3, tagString1, 13);

        Serial.print("From reader 1 : ");
        Serial.println(tagString1);

        if (!gotOne)
            gotOne = true;

        if (tagEqual() && gotOne){
            Serial.println("Item out !");
            gotOne = false;
            clearTag1();
            clearTag2();
        }

        resetReader1(); //eset the RFID reader
    }

}

void checkRFIDReader2(){

    if(Serial2.available() >= 14){

        int readByte = Serial2.read();

        if(readByte != 2)
            return;

        clearTag2();
        Serial2.readBytesUntil(3, tagString2, 13);

        Serial.print("From reader 2 : ");
        Serial.println(tagString2);

        if (!gotOne)
            gotOne = true;

        if (tagEqual() && gotOne){
            Serial.println("Item in !");
            clearTag1();
            clearTag2();
        }

        resetReader2(); //eset the RFID reader
    }

}



void clearTag1(){

    for(int i = 0; i < 13; i++)
        tagString1[i] = 0;
}

void clearTag2(){

    for(int i = 0; i < 13; i++)
        tagString2[i] = 0;
}

boolean emptyTag1(){
    for (int i=0; i<13; i++)
        if (tagString1[i] != 0)
            return false;
    return true;
}

boolean emptyTag2(){
    for (int i=0; i<13; i++)
        if (tagString2[i] != 0)
            return false;
    return true;
}

boolean tagEqual(){

    if(emptyTag1() || emptyTag2())
        return false;

    for(int i = 0; i < 13; i++)
        if(tagString1[i] != tagString2[i])
            return false;

    return true;
}

void resetReader1(){
  ///////////////////////////////////
  //Reset the RFID reader to read again.
  ///////////////////////////////////
  digitalWrite(RFIDResetPin1, LOW);
  digitalWrite(RFIDResetPin1, HIGH);
  delay(150);
}

void resetReader2(){
  ///////////////////////////////////
  //Reset the RFID reader to read again.
  ///////////////////////////////////
  digitalWrite(RFIDResetPin2, LOW);
  digitalWrite(RFIDResetPin2, HIGH);
  delay(150);
}

Did you try swapping the RX and TX pins?