Go Down

Topic: Reading from two RFID readers (Read 39 times) previous topic - next topic

daves_nt_here

I've been using the RDM6300 for a couple years now and had no issues with them running individually. I now have a project that would be nice to combine 2 readers on one nano but I'm having a random issue with the readings.
Most of the time the readers work well but ever so often they garble the data. Any ideas?

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial RFID1(4, 3); // RX and TX
SoftwareSerial RFID2(8, 9); // RX and TX
unsigned long previousMillis = 0; // last time update
int read_Num;

void setup()
{
  RFID2.begin(9600);    // start serial to RFID reader
  RFID1.begin(9600);    // start serial to RFID reader
  Serial.begin(9600);
  Serial.println("Ready");
}
void loop() {
  RFID1.listen();
  delay(75);
  if (RFID1.available() > 0) {
    read_Num = 1;
  }
  if (read_Num == 0) {
    RFID2.listen();
    delay(75);
    if (RFID2.available() > 0) {
      read_Num = 2;
    }
  }
  if (read_Num > 0) {
    char r;

    if (read_Num == 1) {
      while (RFID1.available()) {
        r = RFID1.read();
        Serial.print(r);
      }
    }

    if (read_Num == 2) {
      while (RFID2.available()) {
        r = RFID2.read();
        Serial.print(r);
      }
    }

    Serial.println("");

    delay(5000);

    if (read_Num == 1) {
      while (RFID1.available() > 0) { // Do this after everything else to prevent multiple reads from RFID - Needs 5sec of something before this.
        RFID1.read(); //read it into arduino buffer
        RFID1.flush(); //then flush it
      }
    } else {
      while (RFID2.available() > 0) { // Do this after everything else to prevent multiple reads from RFID - Needs 5sec of something before this.
        RFID2.read(); //read it into arduino buffer
        RFID2.flush(); //then flush it
      }
    }
    read_Num = 0; // Reset read_Num
    Serial.println("Ready");
  }
}

PaulS

Quote
Any ideas?
Yes. Since you have no idea when tags will be presented, you must be listening to both readers at the same time, ALL of the time. SoftwareSerial can not do that.
The art of getting good answers lies in asking good questions.

Go Up