Hello,
I have this dilemma with comparing two RFID Tag numbers using the ID-12 Reader and an Arduino Uno, one from a card, and the other in an array. I'd like to print to Serial: "Card is a Match", then do something. Im manipulating the example from this site:Arduino Playground - ID12
The tag Im trying to compare to:
byte target_tag[TAG_LEN] = {0x4F, 0x00, 0x88, 0xB3, 0x4F};
I cant make up my mind which of these sets of code is the right one to use, as Ive seen them both work in other people's programs, but they wont work for me:
if (bytesread == 12) { // if 12 digit read is complete
Serial.print("5-byte master: ");
for (i=0; i<5; i++) {
if (master[i] < 16) Serial.print("0");
byte master1 = master[i];
Serial.print(master[i], HEX);
Serial.print(" ");
//Serial.println();
}
if(memcmp(master, target_tag[i], TAG_LEN) == 0 )
{
Serial.print("This Card is a Match!");
}
}
Serial.println();
Serial.print("Checksum: ");
Serial.print(master[5], HEX);
Serial.println(master[5] == checksum ? " -- passed." : " -- error.");
Serial.println();
Or this one:
if (bytesread == 12) { // if 12 digit read is complete
Serial.print("5-byte master: ");
for (i=0; i<5; i++) {
if (master[i] < 16) Serial.print("0");
byte master1 = master[i];
Serial.print(master[i], HEX);
Serial.print(" ");
//Serial.println();
}
for(int i = 0; i < ARR_LEN; i++)
{
if (CheckTwoBytes(target_tag[i], master))
{
Serial.print("This Card is a Match!");
}
}
}
Serial.println();
Serial.print("Checksum: ");
Serial.print(master[5], HEX);
Serial.println(master[5] == checksum ? " -- passed." : " -- error.");
Serial.println();
}
boolean CheckTwoBytes ( byte a[], byte b[] )
{
if ( a[0] != NULL ) // Make sure there is something in the array first
match = true; // Assume they match at first
for ( int k = 0; k < 5; k++ ) // Loop 5 times
{
/*
Serial.print("[");
Serial.print(k);
Serial.print("] ReadCard [");
Serial.print(a[k], HEX);
Serial.print("] StoredCard [");
Serial.print(b[k], HEX);
Serial.print("] \n");
*/
if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail
match = false;
}
if ( match ) // Check to see if if match is still true
{
//Serial.print("Strings Match! \n");
return true; // Return true
}
else {
//Serial.print("Strings do not match \n");
return false; // Return false
}
}
Im trying to write the code myself, and learn how it works as Im writing it. I dont feel comfortable just copying and pasting other people's code just to get it to work.
I've searched around the web, and found a variety of help pages, examples and tutorials, but nothing as detailed in explanation as Im looking for.
Any help is greatly appreciated.