TWO RFID Reader

Hi,
I working on my master project. I want connect two RFID Reader (ID-12LA) to an Arduino. I follow http://sree.cc/electronics/how-to-connect-2-rfid-readers-to-an-arduino this sample. I think the code is right. But now, I just can read one reader's code which is pin8. No data come out.

Code:

/*
Connection details :

  1. SOUT pin of RFID1 in to digital pin 8.
  2. SOUT pin of RFID2_out to digital pin 2 .
    */
    #include <SoftwareSerial.h>
    SoftwareSerial nssi1(2, 3);
    SoftwareSerial nssi2(8, 9);
    //RFID
    int val = 0;
    char code[] = " ";
    int bytesread = 0;
    int counter = 0;
    char prev_code[] = "- ";
    int prev_in = 2;
    int p = 0;

void setup()
{
Serial.begin(9600);
nssi1.begin(9600);
nssi2.begin(9600);
Serial.println("Swipe Rfid card");
}

void loop()
{
if (p == 0){ //Each 2 sec scan for each RFIDs
//RFID 1
if(nssi1.available() > 0) { // if data available from reader2

if((val = nssi1.read()) == 10) { // check for heade
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( nssi1.available() > 0) {
val = nssi1.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
}
}
if(bytesread == 10) { // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
Serial.println("Data from 1st RFID");
}
}
else
{
//RFID 2
if(nssi2.available() > 0) { // if data available from reader2

if((val = nssi2.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( nssi2.available() > 0) {
val = nssi2.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
}
}
if(bytesread == 10) { // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
Serial.println("Data from 2nd RFID");
}
}
p = 1-p;
bytesread = 0;
delay(1000);
}

I think it may due to interference?

Thanks a lot.

Hi ysun320

Please edit your post to put the code between code tags. It will make it much easier for people to read it.

I just can read one reader's code which is pin8. No data come out.

Can you clarify exactly what happens when you compile and run your program. Do you get correct data from one reader but not the other?

One thing to check in your program is the declaration of your character buffer for reading the data.

Your code seems to have ...

char code[] = " ";

But the example program you linked to has this:

char code[] = "          ";

The extra spaces between quotes are important to allocate enough space for the data you are reading.

Regards

Ray

Thanks a lot,

But it still doesn't work.

/*
Connection details :
1. SOUT pin of RFID1 in to digital pin 8.
2. SOUT pin of RFID2_out to digital pin 2 .
*/
#include <SoftwareSerial.h>
SoftwareSerial nssi1(2, 3);
SoftwareSerial nssi2(8, 9);
//RFID
int val = 0;
char code[] = "          ";
int bytesread = 0;
int counter = 0;
char prev_code[] = "-         ";
int prev_in = 2;
int p = 0;

void setup()
{
Serial.begin(9600);
nssi1.begin(9600);
nssi2.begin(9600);
Serial.println("Swipe Rfid card");
}

void loop()
{
if (p == 0){ //Each 2 sec scan for each RFIDs
//RFID 1
if(nssi1.available() > 0) { // if data available from reader2

if((val = nssi1.read()) == 10) { // check for heade
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( nssi1.available() > 0) {
val = nssi1.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit 
}
}
}
}
if(bytesread == 10) { // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
Serial.println("Data from 1st RFID");
}
}
else
{
//RFID 2
if(nssi2.available() > 0) { // if data available from reader2

if((val = nssi2.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( nssi2.available() > 0) {
val = nssi2.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
}
}
if(bytesread == 10) { // if 10 digit read is complete
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
Serial.println("Data from 2nd RFID");
}
}
p = 1-p;
bytesread = 0;
delay(500);
}

I get correct data from one reader but not the other. And it works very will when I just one reader.

SoftwareSerial can only receive data from one port at a time. By default, the port is the one that had begin() called last.

In your case, that is why pin 8 works.

It is possible to switch which port you listen on, by adding nssi1.listen() and nssi2.listen() to your program.

However, the problem is knowing which reader is going to be used. If you are listening on nssi1 and the user swipes on nssi2, the data will be lost, I think.

There may be a way around this, but I'm not familiar with RFID readers.

Thanks a lot,
I will try this later.

Thanks

This article may help:

http://bildr.org/2011/02/rfid-arduino/

Thanks

Hi guys,

I work it out. But it still has some problem.
The two ID-12 readers works good. But the data come from the readers have some problem.

my code is :

#include <SoftwareSerial.h>
//SoftwareSerial SSerial(9,8);//rx = digital 1, tx == digital 2
SoftwareSerial SSerial(11,10);

int RFIDResetPin1 = 3; //digital3
int RFIDResetPin2 = 4; //digital4

//Register your RFID tags here
char tag1[13] = "0102ACB7B1A9";
char tag2[13] = "01023C072C14";
char tag3[13] = "01023C013A04";
char tag4[13] = "01023101093A";
char tag5[13] = "01023C0A4376";

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 serial
}


void checkRFIDReader1(){

  //RFID tags are 13+1 characters,
  //so no need to check until we have that many bytes available
  if(Serial.available() >= 6){
    
    

//    char tagString[13]; //this will hold the tag string;

    int readByte = Serial.read(); //read next available byte

    //we MUST start proces at a 2 as it marks the tag begining
    //if it is not a 2, get out of here.
//    if(readByte != 2) return; 

    //buffer to hold our tag
    char tagString[13];
    
//    //read the serial until we gat a 3, the end of the tag
    Serial.readBytesUntil(3, tagString, 13);
     Serial.print("From 1 ");

    checkTag(tagString); //Check if it is a match
    clearTag(tagString); //Clear the char of all value
    resetReader1(); //eset the RFID reader
  }
  
//  delay(1000);

}


void checkRFIDReader2(){

  //RFID tags are 13+1 characters,
  //so no need to check until we have that many bytes available
  if(SSerial.available() >= 6){
    

    //char tagString[13]; //this will hold the tag string;

    int readByte = SSerial.read(); //read next available byte

    //we MUST start proces at a 2 as it marks the tag begining
    //if it is not a 2, get out of here.
//    if(readByte != 2) return; 

    //buffer to hold our tag
    char tagString[13];
    
    //read the serial until we gat a 3, the end of the tag
    SSerial.readBytesUntil(3, tagString, 13);
    Serial.print("From 2 ");
    checkTag(tagString); //Check if it is a match
    clearTag(tagString); //Clear the char of all value
    resetReader2(); //eset the RFID reader
  }
//  delay(1000);

}


void checkTag(char tag[]){
  ///////////////////////////////////
  //Check the read tag against known tags
  ///////////////////////////////////

  if(strlen(tag) == 0) return; //empty, no need to contunue

//  if(compareTag(tag, tag1)){ // if matched tag1, do this
//    Serial.println("tag 1");
//  
//  }else if(compareTag(tag, tag2)){ //if matched tag2, do this
//    Serial.println("tag 2");
//
//  }else if(compareTag(tag, tag3)){
//    Serial.println("tag 3");
//
//  }else if(compareTag(tag, tag4)){
//    Serial.println("tag 4");
//
//  }else if(compareTag(tag, tag5)){
//    Serial.println("tag 5");

//  }
    else{
    Serial.print("Tag: ");
    Serial.println(tag); //read out any unknown tag
  }

}

//void lightLED(int pin){
//  ///////////////////////////////////
//  //Turn on LED on pin "pin" for 250ms
//  ///////////////////////////////////
//  Serial.println(pin);
//
//  digitalWrite(pin, HIGH);
//  delay(250);
//  digitalWrite(pin, LOW);
//}

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);
}

void clearTag(char one[]){
  ///////////////////////////////////
  //clear the char array by filling with null - ASCII 0
  //otherwise, it will think same tag has been read
  ///////////////////////////////////
  for(int i = 0; i < 12; i++){
    one[i] = 0;
  }
}

boolean compareTag(char one[], char two[]){
  ///////////////////////////////////
  //compare two value to see if same,
  //strcmp not working 100% so we do this
  ///////////////////////////////////

  if(strlen(one) == 0) return false; //empty

  for(int i = 0; i < 12; i++){
    if(one[i] != two[i]) return false;
  }

  return true; //no mismatches
}

The out come data from readers:

From 2 Tag: 280005DC8071$ ¼ Ä	 ^
From 1 Tag: 280005DC8071
$ ¼ Â	 ^
From 2 Tag: 
From 2 Tag: 280005DC8071$ ¼ Ä	 ^
From 1 From 1 Tag: 280005DC8071
$ ¼ Â	 ^
From 2 Tag: 
8
From 2 Tag: ÿ 280005DC807$ ¼ Ä	 ^
From 1 From 1 Tag: 280005DC8071
$ ¼ Â	 ^
From 2 Tag: 
0005DC8071
$ ¼ Ä	 ^
From 1 From 1 Tag: 280005DC8071
$ ¼ Â	 ^

Some time one reader read several time, and have Garbled!