Pages: [1]   Go Down
Author Topic: ID-12 programming help  (Read 607 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I have the ID-12 RFID reader, and am trying to set up the programming so I can find the string representation of my id tags. I then want to program it so I can verify them (compare them to the given strings)
I am using the software from the arduino playground.
Code:
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;
    }
  }
}

I do not understand how to store the byte code from the rfid tags, if it wont print to serial because its in bytes. I have tried the conversions such as char() and it gives me errors. Also, I have no idea, once I have the tag code, how to compare tit o the code the reader picks up.
Thanks

-Falven
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bump!....
40 views and not a single reply...
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25847
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Cross-posting won't get you any fans.
Bumping after less than a day isn't looked on kindly either.

Quote
I do not understand how to store the byte code from the rfid tags
They're in "code", aren't they?
« Last Edit: February 08, 2010, 02:08:04 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thougth the reason people weren't posting is because it was in the wrong thread.
Didnt realize it hadn't been exaclty 24 hours.

When you scan a card you can't print it to serial because it's in byte code. Nothing pops up or weird symbols do. How can I scan a card to determine its code and then make variables accordingly to check for it and compare it to whatever card is scanned?
« Last Edit: February 08, 2010, 04:29:53 pm by falven » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25847
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As soon as you've read each character (they're already in ASCII from the reader according to your comments), simply print it out, or use "Serial.print (code, HEX);"
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 55
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
As soon as you've read each character (they're already in ASCII from the reader according to your comments), simply print it out, or use "Serial.print (code, HEX);"

They do print out in ascii by using the Serial.print(code, HEX) function, but Wouldn't i need them in byte format? because they are saved in code[] as byte format, and if you try to compare the code[](byte format) to your cards[](ascii) then they will never match...
Logged

Pages: [1]   Go Up
Jump to: