Storing value from 0-5000 to EEPROM

I have a need to store value from 0-5000 when the power is turned off on my arduino. This really needs to be stored with an accuracy of 1 (I cannot map it down and then map it back up again).

This also cannot be done on a microSD card or similar, I need to do it in eeprom.I thougt about storing each chracter seperately and then multiplying them and adding them together but because of the range of values, I don't think I can do this...

Mowcius

0-5000 fits easily into an "int" (aka "short", aka "int16" or two bytes).
What's the problem?

0-5000 fits easily into an "int" (aka "short", aka "int16" or two bytes).
What's the problem?

You cannot store int values in the EEPROM...

What is wrong with

// save value

int a = value/256;
int b = value % 256;

EEPROM.write(0,a);
EEPROM.write(1,b);

// read value

int a=EEPROM.read(0);
int b=EEPROM.read(1);

value = a*256+b;

You can store bytes in the EEPROM (range 0-255) so your value could be as high as 65535

0-5000 fits easily into an "int" (aka "short", aka "int16" or two bytes).
What's the problem?

I didn't think that you could store anything other than standard bytes 0-255 in EEPROM

I didn't think that you could store anything other than standard bytes 0-255 in EEPROM

You can't store anything but bytes in SRAM either, but don't tell the compiler that. :smiley:

I didn't think that you could store anything other than standard bytes 0-255 in EEPROM

That is all you can store in any sort of memory (well byte orientated which is over 99.9999% of memories).

This is computing everything is in bytes.

EDIT
Beat me to the draw that time. :wink:

Actually, you can't store anything but 0's or 1's in RAM or EEPROM! :slight_smile:

-Mike

Well, 8 bits.. which can be 0 or 1, and 8 bits equals... well, one byte!

lol.

But the EEPROM on board will work with higher numbers, but if you're working with some external EEPROM, well, that requires breaking down of bytes and sending them separately.

This looks helpful...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234477290

But the EEPROM on board will work with higher numbers, but if you're working with some external EEPROM, well, that requires breaking down of bytes and sending them separately.

Ok, so for on board EEPROM you can store bigger numbers simply but for external EEPROM it has to be broken down.

Thanks for the link, I am reading that now!

Mowcius