0

I am trying to run 2 rfid readers (RDM 630) in an Arduino Mega 2560. I just can't figure it out why only one reader will read and the other won't. (The readers are both functional).

#include <SoftwareSerial.h>
SoftwareSerial Reader1(50, 51);
SoftwareSerial Reader2(52, 53);// RX and TX

int rfid, i;
char newtag[14];

void setup()
{
  Reader1.begin(9600);    // start serial to RFID reader
  Reader2.begin(9600);
  Serial.begin(9600);  // start serial to PC 
}

void loop()
{

  if (Reader1.available() > 0) 
  { 
    Serial.println();
    Serial.println();
    Serial.println("Reading RFID Tag...");
    delay(100);

    for (i=0; i < 13; i++)
      {
          rfid = Reader1.read();
          newtag[i]=rfid;
      }
     Reader1.flush();
     Serial.print("RFID Tag No:");
     Serial.print(newtag);

  }

  if (Reader2.available() > 0) 
  {
    Serial.println();
    Serial.println();
    Serial.println("Reading RFID Tag...");
    delay(100);

    for (i=0; i < 13; i++)
      {
          rfid = Reader2.read();
          newtag[i]=rfid;
      }
     Reader2.flush();
     Serial.print("RFID Tag No:");
     Serial.print(newtag);

  }
}
oɔɯǝɹ
  • 7,219
  • 7
  • 58
  • 69
Dayz
  • 21
  • 1
  • 1

2 Answers2

1

SofwareSerial has shared resources so needs a little extra thought on implementation. When you initialise a device it is the listening device. If you initialise another the listening device changes. You need to put:

Reader1.listen();

Before your Reader1 code and switch again for your Reader2 code. See this for example code: http://arduino.cc/en/Tutorial/TwoPortReceive

However, you say you have a Mega. Why not use the multiple serials you have onboard? Your code base will be smaller and the coding is cleaner. http://arduino.cc/en/Tutorial/MultiSerialMega

djUniversal
  • 624
  • 5
  • 7
  • No problem. Have fun with it! – djUniversal Feb 03 '15 at 04:58
  • still have a problem, everytime I swiped the Tag, the serial monitor display the tag no and another 'yyyyyyyyy'.. Is there something wrong with the code? **At Serial monitor:** ` Reading RFID Tag... RFID Tag No:76002C409389 Reading RFID Tag... RFID Tag No:ÿÿÿÿÿÿÿÿÿÿÿÿ Reading RFID Tag... RFID Tag No:76002C408D97 Reading RFID Tag... RFID Tag No:ÿÿÿÿÿÿÿÿÿÿÿÿ ` – Dayz Feb 12 '15 at 16:42
0

After around million of trying and trying I discovered that the correct way to connect 4 RFID RC522 is to put them in the same line on test board except SS pins and the code as usual is ReadUidMultiReader from RFID library like this : enter image description here

Majid Hajibaba
  • 3,105
  • 6
  • 23
  • 55