Seeedstudio RFID reader, garbled data

I am trying to set up a Seeedstudio RFID reader (serial version), and I'm using the code from the thread http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1248988301.

It sort of works, but the data I'm getting gets garbled part way through each read. For example, holding the tag near the antenna will get me an output like:

Tag: [2C00659¹±???]
Tag number: 0
Tag: [2C0065¹¹±???]
Tag number: 0
Tag: [2C0065¹¹±??¦]
Tag number: 0
Tag: [2C00659¹±ÆÃ?]
Tag number: 0
Tag: [2C006599±ÆÃ?]
Tag number: 0
Tag: [2C0065¹¹±??¦]
Tag number: 0
Tag: [2C00659¹±???]
Tag number: 0
Tag: [2C0065¹¹±??¦]
Tag number: 0
Tag: [2C00C3¸²¹±?£]
Tag number: 0

Any idea what's wrong? It's a fairly simple setup, the RFID module is powered from the Arduino, connected to the antenna, and lines going from RX and TX on the RFID module to the software serial TX and RX on the Arduino respectively (though I don't think the RX on the module is actually used).

Thanks.

It looks like software, the numbers from the RFID tag are 64 bits long. that means it with have 32 hex characters in it.
Check you are getting the variable type definition correct so you are reading the right number of bits into it. Half the number looks like it is just garbage. It will not be the hardware because the parity bits would be wrong and you wouldn't get anything.

Thanks for your reply.

The datasheet for the seeedstudio module says I should get 12 data bytes, the first 10 are a 10-digit value if ascii and the last 2 are a checksum. There should also be a leading "0x02" and trailing "0x03". The code should only be storing the middle 12 bytes and dumping it to the serial link to the computer after it gets all 12 digits. (I'm using the UART for communication with the computer and softwareserial for the RFID module).

The software I'm running was provided on the forum thread I linked and from the responses seemed to work. As well it's a fairly simple piece of code which looks to me like it should work (I'm ignoring most of the code like recognizing specific tag values).

Depending on which code you borrowed, it may or may not have been working code. Post the code you have now. It's possible that something you removed as unnecessary really wasn't.

The code is right out of the thread I linked, my only change was the pins used for software serial, but here's the version I'm running:

#include <SoftwareSerial.h>
#define rxPin 6
#define txPin 7

//create a Serial object RFID
SoftwareSerial RFID = SoftwareSerial(rxPin, txPin);
char code[20];

int val = 0;
int bytesread = 0;

char Red[]    = "3900A52D9223";
char Blue[]   = "39009F46D131";
char Yellow[] = "390050448FA2";
char Card1[]  = "210014E221F6";
char Card2[]  = "210014C9906C";

int ledCnt = 5;
int LED[] = {13, 11, 9, 7, 5};

void setup()
{
  Serial.begin(9600); //open serial hardware
  RFID.begin(9600); //open serial software

  pinMode(rxPin, INPUT); //set pin on arduino for receiving RFID data
  pinMode(txPin, OUTPUT); //this is not important

  for(int i=0; i<ledCnt; i++)
  {
    pinMode(LED[i], OUTPUT);
  }
}

void loop()
{
  val = 0;
  bytesread = 0;
  
//  Serial.println("A");

  while(bytesread < 12)
  {
//    Serial.println("B");
    // read 12 digit code
    val = RFID.read();
    if(val == 3)
    { // if header or stop bytes before the 10 digit reading
      break; // stop reading
    }

    if(val != 2)
    {
      code[bytesread] = val; // add the digit
      bytesread++; // ready to read next digit
      code[bytesread] = '\0'; // add the NULL
    }
  }

  if(bytesread >= 12)
  { // if 12 digit read is complete
    Serial.print("Tag: [");
    for(int i=0; i<bytesread; i++)
    {
      Serial.print(code[i]);
    }
    Serial.println("]"); //print the whole 13 bytes
    int tag = FindValidTag(code);
    Serial.print("Tag number: ");
    Serial.println(tag);

    for(int i=0; i<ledCnt; i++)
      digitalWrite(LED[i], LOW);
    if(tag > 0 && tag <= ledCnt)
      digitalWrite(LED[tag-1], HIGH);
  }
}

int FindValidTag(char *code)
{
  if(strcmp(code, Red) == 0)
    return 1;
  else if(strcmp(code, Blue) == 0)
    return 2;
  else if(strcmp(code, Yellow) == 0)
    return 3;
  else if(strcmp(code, Card1) == 0)
    return 4;
  else if(strcmp(code, Card2) == 0)
    return 5;
  else
    return 0;
}

I know your comment is fair, but I'm not the sort to remove code without knowing why.

One guess I have at this point are the read is loading down the power supply to the point the module has a brownout partway through; but with the 500mA supplied by my USB port, I don't think that's too likely.

Another is how vulnerable are these readers to RF interference? I moved the antenna as far from the rest of the circuit as the cable allows (all of 4 inches).

I have not used software serial but it looks like that code is not looking to see if a byte has arrived before it gets read. This means you will read junk bytes towards the end if the whole system is not ready. Given that the raw output speed of an RFID is about 4000 Baud ( that's 125KHz carrier with 32 cycles of carrier per data transferred bit) and you are running the software serial at 9600 baud you can potentially read more data than has actually arrived. Is there a software serial equivalent of serial available?

I had a look at the docs for the software serial library here: http://arduino.cc/en/Reference/SoftwareSerial

There is no equivalent of serial available, but serial read will block until data is available so that seems fine.

There's also a note of timing issues with the mega168 (which I'm using) and it suggests deleting the SoftwareSerial.o file to force it to recompile. I'm using a mac and I've just spent a long time looking though the package contents as well as my hard drive and I can't find where the object files are hidden. I did find the library source code.

The thread linked from the documentation is from 2007 and seems to expect problems with the 168 vs the 8, the mega328 wasn't even a thought back then. It also talks about the problem probably being fixed in Arduino version 8, so this could be completely on the wrong track.

it suggests deleting the SoftwareSerial.o file to force it to recompile.

That no longer applies with Arduino release 17 onwards, this file is regenerated automatically.
It just seems odd that it starts off alight and then drops apart. Do you know if the first characters from the card are correct?

I am running Ardunio 18.

I don't know if the first characters are correct. The tags each have a 10 digit decimal value printed on them, the one I used for the sample I posted is "0006658335", so there is some resemblance. The datasheet says I should get this value as 10 ASCII bytes, and a checksum. All 5 tags in my set only use the digits 0-9 printed on them, yet the examples in the code I borrowed and the values I'm getting from the module also have A-F.

So 0006658335 in hex is 65991F, it looks like you are getting the first byte OK and then it falls apart.
I would try and write something that just looks at the raw bytes coming from the reader and see if you can spot the data in the stream that ensues.

I wrote some code to do what you suggest:

#include <SoftwareSerial.h>
#define rxPin 6
#define txPin 7

//create a Serial object RFID
SoftwareSerial RFID = SoftwareSerial(rxPin, txPin);

int val = 0;

void setup()
{
  Serial.begin(9600); //open serial hardware
  RFID.begin(9600); //open serial software

  pinMode(rxPin, INPUT); //set pin on arduino for receiving RFID data
  pinMode(txPin, OUTPUT); //this is not important
}

void loop()
{
    val = RFID.read();
    Serial.print(val, HEX);
    Serial.print(" ");
}

As each byte comes in from the module, it dumps it to the serial monitor inserting a space between each byte. The result is every time I bring the tag within range of the antenna, I get:

2 99 98 9C A3 81

It's only sent once each time the tag is brought near the antenna, and I always get that complete string.

"2" is the start byte, but "3" is supposed to be the end byte.

It's only sent once each time the tag is brought near the antenna,

Yes that is the way some readers work so that is not a surprise.

I always get that complete string.

Is it always the same with different tags?

It doesn't look very ASCII but it always starts right and I can't see a match between those bytes and the tag number. It looks like 81 is the check sum but it doesn't add up I would expect 72 as the check sum.

It might be that the baud rate of either the receiver or the reader is out but apart from that I can't think what is wrong.