Go Down

Topic: RFID ID-20 + EEPROM (Read 991 times) previous topic - next topic

jp128

Feb 09, 2011, 12:25 pm Last Edit: Feb 09, 2011, 12:27 pm by jp128 Reason: 1
Okay so here is what I have so far.

I have my ID-20 all set up, and working. I have the master key programmed into the code, but I would like to have it put into the EEPROM. In the EEPROM it is set up as follows:

Each brace is a memory spot.
[2] [100] [4] [4] [1] [1] [15] [6] [12] [4] [15] [2] [200] [100] [] [] [] [] [] [] [] [] [] [] [200] ....

So the first number is 2, meaning there are 2 RFID tags in the EEPROM and that is all the program should search for. The second number, 100, means that the next 10 locations are part of an RFID tag. Once it reaches 200, it knows to stop.

With the program that I have for my RFID reader, it gives me a character array with ten elements. These are hex values of the RFID tag, but when they are written and then read, it is an integer.

Quote

 if (Serial.available() > 0 ) {
   char IDstring[13];
   if ( (val = Serial.read()) == 02 ) {
     for (int i = 0; (val = Serial.read()) != 03 ; i++) {
     IDstring = val;
     IDstring[10] = 0x00;  
     String ID = "";
     for(int i = 0; i < 10; i++)
     ID += IDstring;
     if(isValid(ID)){
       lcdPrintMsg("Access granted. ","Welcome back!!! ");
       ledLight(1);
       changeLockPosition();
       delay(1000);
     } else {
       lcdPrintMsg("Invalid ID tag, ","access denied!  ");
       ledLight(2);
       lcd.setCursor(16,1);
       delay(1000);
     }
     resetID12();                // reset after a valid read
   }
 }



That is my code that gets the ID of the tag, which works fine. I run into the problem of when I try to check to see if it is valid.

I am just wondering how I should store the RFID tags in the memory, and how I should go about retrieving them and comparing them.

Should I be sending the function the char array IDstring variable or the string ID variable? Which would be easiest to compare?

Thanks
John-Paul
Geek Squad - Getting Geekier :D

PaulS

Quote
With the program that I have for my RFID reader, it gives me a character array with ten elements. These are hex values of the RFID tag, but when they are written and then read, it is an integer.

Whether the value that is stored in a memory location is DISPLAYED as a base 2 value (binary), base 8 value (octal), base 10 value (decimal), or base 16 value (hexadecimal) has absolutely no relationship to what value is stored in that location.

Quote
I run into the problem of when I try to check to see if it is valid.

What problem is that? What does the isValid() function look like?

Quote
I am just wondering how I should store the RFID tags in the memory, and how I should go about retrieving them and comparing them.

Seems to me like you have already outlined how you will do that.

Quote
Should I be sending the function the char array IDstring variable or the string ID variable? Which would be easiest to compare?

If you send the String object, you can use the isEqual() function or == operator. If the send the char array, you can use the strcmp() function. Seems like a tossup to me.

jp128

Okay, here is what my isValid function looks like. I am sure it will work fine if just store the keys as a string.

Quote

boolean isValid(String ID1){
  
  for(int i = 0; i < 15; i++){
      if(ID1 == validKeys)
        return true;
  }  
  return false;
  
}



I guess my question then is retrieving the data. When I do something like EEPROM.read(i) I get a base 10 number. Is there an easy way to make that into hex?
John-Paul
Geek Squad - Getting Geekier :D

jp128

Nevermind, I believe I answered my own question. I will reply if I come across anything else. Thanks :D
John-Paul
Geek Squad - Getting Geekier :D

PaulS

Code: [Select]
for(int i = 0; i < 15; i++){
      if(ID1 == validKeys)
        return true;
  } 

You are comparing the same two values 15 times. How is that working out for you?

jp128

It is supposed to read
Code: [Select]
validKeys[i].

I have it correct in my code, it just wasn't copied corrected because of forum code I think.
John-Paul
Geek Squad - Getting Geekier :D

Go Up