Mega + Multiple RFIDs

Hi all.

I would like to ask you if it is possible to connect multiple RFID readers (RDM6300) to an Arduino Mega.
Do you know what is the maximum number of sensors that it can be allowed?

Thanks

if it is possible to connect multiple RFID readers (RDM6300) to an Arduino Mega

Yes

Do you know what is the maximum number of sensors that it can be allowed?

You can have three attached because they have a serial output and the Mega has four serial ports. ( one is needed for talking to the computer ).

Great! Thanks a lot.
I will try that

So, I am trying the following code to get data from the Serial Port 1 (pin 19 on the Mega), but I don’t see anything happening…
I have tried echoing the data to the Serial port (0), but nothing. Also tried to use the onboard LED and check if something is happening but again, it doesn’t work.
Am I using the Serial1 correctly?

#include <SoftwareSerial.h>
#include <avr/pgmspace.h>

#define RxPin1 19 //Pin to read data 
#define TxPin1 18 //Pin to write data  

prog_char tag_0[] PROGMEM = "45009F4923B0"; //black
prog_char tag_1[] PROGMEM = "720023552327"; //blue
prog_char tag_2[] PROGMEM = "6E0069DF2AF2"; //pink
prog_char tag_3[] PROGMEM = "52002F02FC83"; //red
prog_char tag_4[] PROGMEM = "6E00693392A6"; //white
prog_char tag_5[] PROGMEM = "52002EB54D84"; //yellow
prog_char tag_6[] PROGMEM = "6E0069B674C5"; //orange

PROGMEM const char *tag_table[] = {   
  tag_0,
  tag_1,
  tag_2,
  tag_3,
  tag_4,
  tag_5,
  tag_6 };
//----

SoftwareSerial rfidReader1(RxPin1, TxPin1);

String tagString;
char tagNumber[14];
boolean receivedTag;

void setup() {
  Serial.begin(9600);
  
  Serial1.begin(9600);
  while (!Serial1) ;
  rfidReader1.begin(9600); // the RDM6300 runs at 9600bps
  Serial1.println("RFID1 Reader...ready!");
}

void loop() {
  receivedTag=false;
  while (rfidReader1.available()){
    Serial1.println("rfid 1 available");
    int BytesRead = rfidReader1.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag 
    receivedTag=true;
  }  

  if (receivedTag){
    tagString=tagNumber;
    Serial1.println();
    Serial1.print("Tag Number: ");
    Serial1.println(tagString);

    if (checkTag(tagString)){
      Serial1.print("Tag Authorized...");
    }
    else{
      Serial1.print("Unauthorized Tag: ");
      Serial1.println(tagString);
      delay(1500); // a delay of 1500ms and a flush() seems to stop tag repeats
      rfidReader1.flush();
    }
    memset(tagNumber,0,sizeof(tagNumber)); //erase tagNumber
  }   
}

boolean checkTag(String tag){
  char testTag[14];
  for (int i = 0; i < sizeof(tag_table)/2; i++) {
    strcpy_P(testTag, (char*)pgm_read_word(&(tag_table[i])));
    if(tag.substring(1,13)==testTag){//substring function removes SOT and EOT
      return true;
      break;
    }
  }
  return false;
}

It looks like you're mixing up your serial ports. You seem to be sending stuff on serial 1 when you say that is what you have your reader connected to.
Does the reader use 9600 baud? A lot do not.
You also have software serial, I don't think that works on the mega.

So debug on serial and read from the RFID reader on serial1.

Try again, and post your results and say how you have wired things up.

Ohhh, I see my mistakes.

I skipped the software serial as I am using the hardware serial ports. I have also used the Serial to debug and Serial1 to read the data from the RFID, which operates at 9600.

Im not receiving data. Maybe it is something obvious for someone else?

#define RxPin1 19 //Pin to read data 
#define TxPin1 18 //Pin to write data 

prog_char tag_0[] PROGMEM = "45009F4923B0"; //black
prog_char tag_1[] PROGMEM = "720023552327"; //blue
prog_char tag_2[] PROGMEM = "6E0069DF2AF2"; //pink
prog_char tag_3[] PROGMEM = "52002F02FC83"; //red
prog_char tag_4[] PROGMEM = "6E00693392A6"; //white
prog_char tag_5[] PROGMEM = "52002EB54D84"; //yellow
prog_char tag_6[] PROGMEM = "6E0069B674C5"; //orange

PROGMEM const char *tag_table[] = {   
  tag_0,
  tag_1,
  tag_2,
  tag_3,
  tag_4,
  tag_5,
  tag_6 };

String tagString;
char tagNumber[14];
boolean receivedTag;

void setup() {
  Serial.begin(9600);
  
  while (!Serial1) ;
  Serial1.begin(9600); // the RDM6300 runs at 9600bps
  
  Serial.println("RFID1 Reader...ready!");
}

void loop() {
  receivedTag=false;
  while (Serial1.available()){
    Serial.println("rfid 1 available");
    int BytesRead = Serial1.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag 
    Serial.println(BytesRead);
    receivedTag=true;
  }  

  if (receivedTag){
    tagString=tagNumber;
    Serial.println();
    Serial.print("Tag Number: ");
    Serial.println(tagString);

    if (checkTag(tagString)){
      Serial.print("Tag Authorized...");
    }
    else{
      Serial.print("Unauthorized Tag: ");
      Serial.println(tagString);
      delay(1500); // a delay of 1500ms and a flush() seems to stop tag repeats
      Serial1.flush();
    }
    memset(tagNumber,0,sizeof(tagNumber)); //erase tagNumber
  }   
}

boolean checkTag(String tag){
  char testTag[14];
  for (int i = 0; i < sizeof(tag_table)/2; i++) {
    strcpy_P(testTag, (char*)pgm_read_word(&(tag_table[i])));
    if(tag.substring(1,13)==testTag){//substring function removes SOT and EOT
      return true;
      break;
    }
  }
  return false;
}
int BytesRead =

So you are putting all the bytes from your reader into one int?

Do you get the ready to read message?

Is there still no response from the token being presented, that is it never says "rfid 1 available"

You don't need

while (!Serial1) ;

In the setup.

The same sketch (with SoftwareSerial) works fine in Uno.

This is stuck in the message "RFID1 Reader...ready!" in setup.

If I get rid of the while (Serial1.available()) I can read the int BytesRead but I always get a 0.

Is there another way to see what is happening in Serial1 and if messages are passing through?

In that case it implies you haven't wired it up correctly.

char tagNumber[14];

Serial1.readBytesUntil(3, tagNumber, 15);

So you have 14 bytes allocated to tagNumber array and yet you tell the readBytesUntil you have allocated 15?

I have adjusted the bytes accordingly.
The sketch works in Uno as I said before with exactly the same setup. Only the board changes and the hardware serial.
The connections are exactly the same. RFID connects to power, ground, and RX pin 19 on Mega.
:confused:

Follow-up:

Changed jumper wires and RFIDs and now everything works fine. Here is the final code for reading three RFIDs with the Mega.

#define RxPin1 19 //Pin to read data 
#define TxPin1 18 //Pin to write data 

#define RxPin2 17 //Pin to read data 
#define TxPin2 16 //Pin to write data 

#define RxPin3 15 //Pin to read data 
#define TxPin3 14 //Pin to write data 

prog_char tag_0[] PROGMEM = "45009F4923B0"; //black
prog_char tag_1[] PROGMEM = "720023552327"; //blue
prog_char tag_2[] PROGMEM = "6E0069DF2AF2"; //pink
prog_char tag_3[] PROGMEM = "52002F02FC83"; //red
prog_char tag_4[] PROGMEM = "6E00693392A6"; //white
prog_char tag_5[] PROGMEM = "52002EB54D84"; //yellow
prog_char tag_6[] PROGMEM = "6E0069B674C5"; //orange

PROGMEM const char *tag_table[] = {   
  tag_0,
  tag_1,
  tag_2,
  tag_3,
  tag_4,
  tag_5,
  tag_6 };

String tagString;
char tagNumber[14];
boolean receivedTag;

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

  //while (!Serial1) ;
  Serial1.begin(9600); // the RDM6300 runs at 9600bps
  Serial.println("RFID1 Reader...ready!");
  Serial2.begin(9600); // the RDM6300 runs at 9600bps
  Serial.println("RFID2 Reader...ready!");
  Serial3.begin(9600); // the RDM6300 runs at 9600bps  
  Serial.println("RFID3 Reader...ready!");
}

void loop() {
  receivedTag=false;
  while (Serial1.available()){
    Serial.println("rfid 1 available");
    int BytesRead = Serial1.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag 
    Serial.println(BytesRead);
    receivedTag=true;
  }  

  while (Serial2.available()){
    Serial.println("rfid 2 available");
    int BytesRead = Serial2.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag 
    Serial.println(BytesRead);
    receivedTag=true;
  }  

  while (Serial3.available()){
    Serial.println("rfid 3 available");
    int BytesRead = Serial3.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag 
    Serial.println(BytesRead);
    receivedTag=true;
  }  

  if (receivedTag){
    tagString=tagNumber;
    Serial.println();
    Serial.print("Tag Number: ");
    Serial.println(tagString);

    if (checkTag(tagString)){
      Serial.print("Tag Authorized...");
    }
    else{
      Serial.print("Unauthorized Tag: ");
      Serial.println(tagString);
      delay(1500); // a delay of 1500ms and a flush() seems to stop tag repeats
      Serial1.flush();
      Serial2.flush();
      Serial3.flush();
    }
    memset(tagNumber,0,sizeof(tagNumber)); //erase tagNumber
  }   
}

boolean checkTag(String tag){
  char testTag[14];
  for (int i = 0; i < sizeof(tag_table)/2; i++) {
    strcpy_P(testTag, (char*)pgm_read_word(&(tag_table[i])));
    if(tag.substring(1,13)==testTag){//substring function removes SOT and EOT
      return true;
      break;
    }
  }
  return false;
}

Glad you got it working.

Changed jumper wires

Can you be more specific please, then we can get the maximum advantage from this thread.

I am not sure why the RFID didn’t work properly. I didn’t check all the jumper wires connected to the RFIDs, but my suspicion is that something didn’t make correct contact. So, my advice to a similar situation, to measure the wires (for possible malfunctions)