RDM6300 125kHz reader

Hi,

can someone please help me understand the RDM6300 reader and how can I optimize the code, to read just one correct value?

For testing Iam using just simple code below, but when I put the chip or card close to the reader even only for a short while, the reader makes like 4 different reads in that short while and the last one or two are “corrupted” - as I move the chip away I guess it reads only some of ID characters in that last attempts so the rest is just some gibberish.

So lets say I put the chip close to the reader, what I need is get the ID and do …SOME CODE… But so far becuase it reads the chip like 4 or 5 times in second or so, the code for that DO SOMETHING (no matter what delay I set) is repeating for that same number of times even when the chip is no longer nowhere near that reader. I maybe dond understand how the loop works becuase I would assume if there is delay about 3 seconds after successful read, the another loop will not have any data because after 3 seconds the chip is long gone from the reader so I have no idea why it keeps running for another 2 or 3 times…

#define RX 2
#include <SoftwareSerial.h>
SoftwareSerial RFID(RX, 0);
char prijateID[14];
char ulozeneID[10] = {'1', '2', '3', '0', '4', '0', '2', '8', '1', '5'};

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

void loop() {

  if (RFID.available() > 0) {

    for (int i = 0; i < 14; i++) {
      prijateID[i] = RFID.read();
    }
    Serial.print("ID: ");
    // ID is on position 2-11,
    for (int i = 1; i < 11; i++) {
      Serial.print(prijateID[i]);
      Serial.print(" ");
    }

    bool neshoda = 0;
    // we will check all chars
    for (int i = 1; i < 11; i++) {
      // if some of the chars do not match      
      if (prijateID[i] != ulozeneID[i - 1]) {
        neshoda = 1;
      }
    }
    if (neshoda == 1) {
      Serial.println("| The saved tag do not matches!");
    }
    else {
      Serial.println("| The saved tag matches!");
    }
    // pause after succesful read
    delay(3000);
  }
  // pause before new loop
  delay(500);
}
  if (RFID.available() > 0) {

    for (int i = 0; i < 14; i++) {
      prijateID[i] = RFID.read();
    }

If there is at least one byte available to read, read all 14 of them. Why doesn’t this seem like a good idea?

Because it is NOT.

OK can you pleas be more specific? How else should I read the ID?

PaulS:

  if (RFID.available() > 0) {

for (int i = 0; i < 14; i++) {
      prijateID[i] = RFID.read();
    }



If there is at least one byte available to read, read all 14 of them. Why doesn't this seem like a good idea?

Because it is NOT.

Here is a tutorial explaining how RDM6300 works (with a code example).

@OP

Instead, try this:

byte n = RFID.available();
if(n == 14)
{
    for (int i = 0; i < 14; i++) 
    {
      prijateID[i] = RFID.read();
    }
}

How else should I read the ID?

If you KNOW that there will be 14 bytes of data to read, when it all arrives, don't read anything until there ARE 14 bytes available.

There must be something in the 14 bytes that indicates that the packet is starting/complete/good. It would be better to use THAT information to read the data as it arrives, and use the data only when it is complete/good.

GolamMostafa:
@OP

Instead, try this:

byte n = RFID.available();

if(n == 14)
{
    for (int i = 0; i < 14; i++)
    {
      prijateID[i] = RFID.read();
    }
}

Bad idea. Suppose that, for some reason or another, the Arduino didn’t execute that code until there were 15 or 16 or 64 bytes of data in the buffer. You’d never read any data again.

Far better to read the data when there are 14 OR MORE bytes available.

vlc0617:
Here is a tutorial explaining how RDM6300 works (with a code example).

RFID Readers RDM6300 and RDM630 (Arduino-Tutorial) | UATS A&S #15 - YouTube

Thanks, I tried this code also, but I cant use it in the final project, becuase Iam using also TMRpcm.h and they both use same resources and cant work together. Therefore I used the more simple code that I added in my post, which works with TMRpcm.h. I just dont how exactly how I should optimize the multiple reading

@OP

PaulS:
If you KNOW that there will be 14 bytes of data to read, when it all arrives, don't read anything until there ARE 14 bytes available.

There must be something in the 14 bytes that indicates that the packet is starting/complete/good. It would be better to use THAT information to read the data as it arrives, and use the data only when it is complete/good.

1. Looks like that the following one is the specification for the 'transmission frame' of your RFID card.
RFID.png

The message (transmission frame) coming from the RFID/RDM Card --
begins with the binary coded value 0x02h (start mark)
contains ASCII coded values (10 charcaters) for data.
contains 2-byte ASCII coded values for the 2-digits (1-byte) of checksum
ends with binary coded value 0x03 (end mark)

The transmission frame length is: 14 bytes.

2. Write codes for your receiver to comply with above specifications and above quoted post.

3. Please, post your codes as we are interested to see how you are detecting 0x02 (the start mark), 0x03 (the end mark); receiving and storing data bytes; performing 'data validity' by comparing the 'computed checksum' with that of the 'received checksum'. (You may ask for assistance in coding if you feel that you need!)

RFID.png