RFID Tag Reader

Hi,
My first project and my first post here :wink:

I bought a TWT2021 at Conrad:

http://shop.conrad-uk.com/1/2-a1-uk0191553__191553-universal-rfid-antenna-c-control-twt2021-.html

Datasheet:

And somehow i dont manage to get it working. The tag is fine, Arduino (UNO) works and i ve tried this code for example, but simple rx to tx, too:

void setup() {
  Serial.begin(9600);                                 // connect to the serial port
}

void loop () {
  byte i = 0;
  byte val = 0;
  byte code[6];
  byte checksum = 0;
  byte bytesread = 0;
  byte tempbyte = 0;

  if(Serial.available() > 0) {
    if((val = Serial.read()) == 2) {                  // check for header 
      bytesread = 0; 
      while (bytesread < 12) {                        // read 10 digit code + 2 digit checksum
        if( Serial.available() > 0) { 
          val = Serial.read();
          if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) { // if header or stop bytes before the 10 digit reading 
            break;                                    // stop reading
          }

          // Do Ascii/Hex conversion:
          if ((val >= '0') && (val <= '9')) {
            val = val - '0';
          } else if ((val >= 'A') && (val <= 'F')) {
            val = 10 + val - 'A';
          }

          // Every two hex-digits, add byte to code:
          if (bytesread & 1 == 1) {
            // make some space for this hex-digit by
            // shifting the previous hex-digit with 4 bits to the left:
            code[bytesread >> 1] = (val | (tempbyte << 4));

            if (bytesread >> 1 != 5) {                // If we're at the checksum byte,
              checksum ^= code[bytesread >> 1];       // Calculate the checksum... (XOR)
            };
          } else {
            tempbyte = val;                           // Store the first hex digit first...
          };

          bytesread++;                                // ready to read next digit
        } 
      } 

      // Output to Serial:

      if (bytesread == 12) {                          // if 12 digit read is complete
        Serial.print("5-byte code: ");
        for (i=0; i<5; i++) {
          if (code[i] < 16) Serial.print("0");
          Serial.print(code[i], HEX);
          Serial.print(" ");
        }
        Serial.println();

        Serial.print("Checksum: ");
        Serial.print(code[5], HEX);
        Serial.println(code[5] == checksum ? " -- passed." : " -- error.");
        Serial.println();
      }

      bytesread = 0;
    }
  }
}

Its from here:
http://www.arduino.cc/playground/Code/ID12

And what do i receive? Nothing :~
Neither at 3.3 v, nor at 5, though i measure an output voltage at the serial cable of the RFID reader, so it has to be something softwaresided.

As usual considering posts of newbees it probably will be a simple thing, but i cant figure out, what is missing and would appreciate any help :smiley:

Now i wish, i would have bought an ID12 or 20…

PS: Somewhere in the datasheet i read something about the need of a max232 inverter in order to connect the module to rs232, which is not necessary for the id-series.
Could that be the mistake?

Thanks, Greets, Flok3r

so it has to be something softwaresided.

Probably. Serial data is sent ssslllooowwwlllyyy, at least using the Arduino clock. On each pass through loop, you are reading one byte, to see if it is the start of the data from the RFID. If it is, you read the rest of the data. There is likely none.

On subsequent passes, you read the next byte, looking for another start byte.

Your array to hold the data goes out of scope at the end of loop, as does your array index.

What you need to do is look for the start bit, as you are doing now, then have a while loop that reads data, and keeps looping until the end bit (or the right number of bytes) has been read.