# EEPROM write letters?

http://arduino.cc/en/Reference/EEPROMWrite states that the value has to be from 0 to 255. How can I write letters into the EEPROM?

For example if I want to store the RFID of 00365F8BDF

You'll notice that all the "letters" in that RFID are hex digits. You'll use half the memory if you store them as binary, than if you store them as ASCII characters (5 bytes vs. 10 bytes).

The RFID ID is in fact a hexadecimal number. A hexadecimal (or hex) number stored in a single byte(or eight bits) can range from 00 (0 binary, 0 decimal) to FF (11111111 binary, 255 decimal). You can store it in EEPROM in many ways, one of which is to regard every couple of digits as a single byte number and thus store in EEPROM a sequence of 5 bytes. I guess it depends on the way you receive the ID from a reader driver, so you can easily compare the incoming ID with the stored in EEPROM one.

Awesome, got it, thanks!

Extra for other people who stumble here: I think i'll do 2 at a time, seems to be fairly standard from what I've read.

Example: 04 11 C0 23 EB would be 4 17 192 35 235

04 11 C0 23 EB would be 0x04 0x11 0xC0 0x23 0xEB

I mean after it's converted to decimal so that I can store it in the Adruino's eeprom.

I mean after it's converted to decimal so that I can store it in the Adruino's eeprom.

Why bother converting? It's more error-prone. If someone gives you a hex value, store it as a hex value.

It's funny, right before I saw your last reply I ran into an RFID card that's first two digits where 00. Talk about problems lol. I was using someone else's code who stores it in decimal every 2 characters but that's not going to work with a card where 00 can happen.

Can you post some example code for storing hex in the arduino's eeprom? I'm confused since it says it can only store 0 - 255 in each address.

I was using someone else's code who stores it in decimal every 2 characters but that's not going to work with a card where 00 can happen.

Why not? You can store a 0 in EEPROM.

A byte (like an EEPROM location) can hold one of 256 distinct values, from 0 to 255 inclusive.
256 = 28, since a byte has eight bits.
A convenient way of representing eight bit numbers is as two hex digits.
Hex digits occupy four bits, and go 0…9 then A…F.

So, decimal 10 is hex 0A, written in C as 0x0A.
255 decimal is 0xFF ((15* 16) + 15 = 255), and zero decimal is 0x00.

16 decimal is 0x10 (1 * 16) + 0 = 16).
32 decimal is 0x20 (2 * 16) + 0 = 32).

Why not? You can store a 0 in EEPROM.

But both 0 and 00 in hex come out to 0 in decimal. When I read it back out it can't know if it was meant to be 0 or 00. Please correct me if i'm wrong.

You're ...wrong ;D

Zero is zero (nada, rien, zippo, zilch...) whether you represent it as 00 or 0, or even in 32 bit cases as 0x00000000.

I guess i'm having another issue then. With the code i'm using I can scan and store all the RFIDs that I have except this one that starts with 00.

With the code i'm using I can scan

Maybe if you posted it, we could help. Please use the "#" button in the editor's toolbar.

I'm still not clear on how to store hex values in EEPROM. Here's the code i'm using. I tried to post with the CODE tags but couldn't fit it all in. It's rather long but a lot of it isn't relevant to this (LED, master card).

http://www.thelanhouse.net/id20.pde

I'm still not clear on how to store hex values in EEPROM

The same way you store decimal values in EEPROM - they're the same numbers, just the representation is different.

e.g. 0x1A = B00011010 = 032 = 26

Your writeID method looks right to me. Is there a problem with it?

I have these 4 IDs:

card 2500ABD6134B implant 00365F8BDF3D key 0411C023EB1D key2 04613AF98127

The last 2 digits are the checksum. This is a dump of the eeprom after storing the Implant and key.

0 2

1 0 2 54 3 95 4 139 5 223

6 4 7 17 8 192 9 35 10 235

The first one, 0, is set to 2 because 2 keys are stored.

For some reason, even though it looks like it's stored correctly, it won't recognize the implant as a valid key.

For some reason, even though it looks like it's stored correctly, it won't recognize the implant as a valid key.

I'm sorry that I don't quite understand this. When you say "it won't recognize...", what exactly is "it"?

This will return either “It’s stored” or “It’s NOT stored”. It keeps returning “It’s NOT stored” for the implant but returns “It’s stored” for the other RFIDs.

``````  {
if(Serial.available() > 0)          // If the serial port is available and sending data...
{
if((val = Serial.read()) == 2)    // First Byte should be 2, STX byte
{
getID();                        // Get the ID, sets readCard = to the read ID

for ( int i = 0; i < 5; i++ )         // Loop 5 times
{
if  ( readCard[i] < 16 )              // Print out 0 if < 16 to prepend output
Serial.print("0");

Serial.print(" ");
}
Serial.println();
Serial.print("Checksum: ");

if ( readCard[5] == checksum )        // See if the 5th BYTE (the checksum) read in from the reader
{                                     // matches the checksum caculated
checksum = 0;          // If so, we can empty the variable storing the calculated checksum
Serial.println();
Serial.println("Checksum correct");
Serial.println();
if ( isMaster( readCard ) )         // Check to see if the card is the master programing card
{
programMode = true;               // If so, enable programing mode
}
else
{
if ( findID(readCard) )           // If not, see if the card is in the EEPROM
{
openDoor(5);                // If it is, open the door lock
Serial.println();
Serial.print("It's stored");
Serial.println();
}
else
{
failed();                       // If not, show that the ID was not valid
Serial.println();
Serial.print("It's NOT stored");
Serial.println();
}
}
}
else                                  // If the checksum failed
{                                     // Print out the checksum

Serial.println("Checksum error");
Serial.println();
Serial.print("[");
Serial.print("] != [");
Serial.print(checksum, HEX);
Serial.print("] ");

}
}
}
}
}
``````
``````// Looks in the EEPROM to try to match any of the EEPROM ID's with the passed ID
boolean findID( byte find[] )
{
int count = EEPROM.read(0);             // Read the first Byte of EEPROM that
// Serial.print("Count: ");                // stores the number of ID's in EEPROM
// Serial.print(count);
//Serial.print("\n");
for ( int i = 1; i <= count; i++ )      // Loop once for each EEPROM entry
{
readID(i);                            // Read an ID from EEPROM, it is stored in storedCard[6]
if( checkTwo( find, storedCard ) )    // Check to see if the storedCard read from EEPROM
{                                     // is the same as the find[] ID card passed
//Serial.print("We have a matched card!!! \n");
return true;
break;                              // Stop looking we found it
}
else                                  // If not, return false
{
//Serial.print("No Match here.... \n");
}

}
return false;
}
``````