Problems with RDM630 RFID reader

Hi there,

I'm currently doing some tests with Arduino and an RDM630 RFID-reader, but the RFID reader is behaving a little strange.

The circuit is fairly simple and the sketch simple as well. The output of the RFID reader is connected to arduino pin #2 which is being read by a SoftwareSerial object. When a code is read it is being compared against seven different know codes and depending on the code that was read the appropriate led is flashed for 25msec.

Howerver, it seems that in my construction the arduino is not receiving rfid codes in a consistent way. Sometimes the RFID reader sends the codes fluently, sometimes it "stalls", sometimes it stops sending no codes at all, sometimes it sends one code only when I'm bring a tag close to the antenna or when taking it away, etc. This youtube video is demonstrating the behavior of the circuit:

Initially I thought that it must be a connection problem with the antenna (like a broken soldering or cable), but I ended up soldering the antenna directly onto the RFID reader board and I got the exact same results.

This is the circuit diagram (sorry for the bad quality and the hand-drawing):

This is the sketch-code:

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

#define ledPinBase 4

SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);

#define numOfTags 7

char *known_codes[] = {
  " 2 52 53 48 48 66 56 66 70 50 53 54 55 3",
  " 2 51 68 48 48 65 56 54 53 56 66 55 66 3",
  " 2 51 67 48 48 67 68 48 52 55 68 56 56 3",
  " 2 52 52 48 48 69 55 48 52 51 70 57 56 3",
  " 2 48 49 48 55 69 69 56 50 56 66 69 49 3",
  " 2 52 53 48 48 66 56 70 70 57 49 57 51 3",
  " 2 48 48 51 54 53 70 56 67 49 65 70 70 3",
};

void setup()
{
  Serial.begin(9600);
  RFID.begin(9600);
  pinMode(rxPin,INPUT);
  for (int i = 0; i < numOfTags; i++) {
    pinMode(ledPinBase+i,OUTPUT);
    digitalWrite(ledPinBase+i,LOW);
  }
}

char code[1024];

void loop()
{
  if (RFID.available()) {
    code[0] = '\0';
    int values = 0;
    while (RFID.available() && values++ < 14) {
      int val = RFID.read();
      sprintf(code,"%s %d",code,val);
    }
    Serial.println(code);
    int tag = -1;
    for (int i = 0; i < numOfTags; i++) {
      if (strcmp(known_codes[i],code) == 0) {
        tag = i;
        break;
      }
    }
    if (tag != -1) {
      digitalWrite(ledPinBase+tag,HIGH);
      delay(25);
      digitalWrite(ledPinBase+tag,LOW);
    }
  }
  delay(25);
}

The code is not the best possible but this is roughly a prototype/test so this is not the import thing right now.

Any ideas what is going wrong?

Thank you in advance.
Giannis

We can't see your Serial Monitor from here. Perhaps if you post the pile of debug output you get and add notes explaining why the output is not what you expected we would have a better chance of being able to help.

One issue is that you appear to grab 14 bytes without checking to see if the first byte is a 2. If a character is lost the reading will get out of synchronization. The reason to have a START and END characters is to allow for loss of data.

johnwasser:
One issue is that you appear to grab 14 bytes without checking to see if the first byte is a 2. If a character is lost the reading will get out of synchronization. The reason to have a START and END characters is to allow for loss of data.

You are absolutely correct, that was the problem indeed! I checked the Serial Monitor and I saw "broken" sequences coming up as separate rfid codes at the times it was "not working". I changed the code a bit to always wait for the initial "2" and only return a code after the ending "3', now it works "like a charm", Thank you very very much! :slight_smile:

Just in case, here is the new corrected code that works:

#include <SoftwareSerial.h>

#define RX_PIN 2
#define TX_PIN 3

#define LED_PIN_BASE 4

SoftwareSerial RFID = SoftwareSerial( RX_PIN, TX_PIN );

#define NUM_OF_TAGS 7

char *known_codes[] = {
  " 2 52 53 48 48 66 56 66 70 50 53 54 55 3",
  " 2 51 68 48 48 65 56 54 53 56 66 55 66 3",
  " 2 51 67 48 48 67 68 48 52 55 68 56 56 3",
  " 2 52 52 48 48 69 55 48 52 51 70 57 56 3",
  " 2 48 49 48 55 69 69 56 50 56 66 69 49 3",
  " 2 52 53 48 48 66 56 70 70 57 49 57 51 3",
  " 2 48 48 51 54 53 70 56 67 49 65 70 70 3",
};

void setup()
{
  Serial.begin(9600);
  RFID.begin(9600);
  pinMode(RX_PIN,INPUT);
  for (int i = 0; i < NUM_OF_TAGS; i++) {
    pinMode(LED_PIN_BASE+i,OUTPUT);
    digitalWrite(LED_PIN_BASE+i,LOW);
  }
}

void loop()
{
  char *code = get_code();
  if (code) {
    Serial.println(code);
    int tag = -1;
    for (int i = 0; i < NUM_OF_TAGS; i++) {
      if (strcmp(known_codes[i],code) == 0) {
        tag = i;
        break;
      }
    }
    if (tag != -1) {
      digitalWrite(LED_PIN_BASE+tag,HIGH);
      delay(25);
      digitalWrite(LED_PIN_BASE+tag,LOW);
    }
  }
  delay(25);
}

char buffer[1024] = "\0";

char *get_code() {
  while (RFID.available()) {
    int val = RFID.read();
    if (val == 2) {
      buffer[0] = '\0';
    }
    sprintf(buffer,"%s %d",buffer,val);
    if (val == 3) {
      return buffer;
    }
  }
  return NULL;
}