EEPROM

Hi there, I wanted to know if the EEPROM has default values of 0, or of they are set to null.

If i wanted to initialize a value to the EEPROM, and increment it each time the arduino powers on, where would i place my initial
EEPROM.write(0,value);

would it be in the setup();?

basically ill be doing something within the loop like this

value = EEPROM.read(0);
value++;
EEPROM.write(0,value);

there all 255 unless you have changed them before

EEPROM is not modified at all, during the sketch upload process. As Ste Hughes said, a factory fresh EEPROM should have 0xFF in all bytes. But I wouldn't rely on that, and since I often re-use old Arduino boards to prototype new projects, I can't assume that the EEPROM has those fresh 0xFF contents.

You could make a dedicated EEPROM-wiping sketch that just fills it with 0xFF, and run that once before you run an important sketch that assumes the board is fresh.

A valuable alternative trick is to have a "version number" or "schema" in your code, and use an EEPROM location that holds the version number of the software that wrote anything to the EEPROM. If you change your software such that EEPROM locations or meanings are different, or you just need a reset, just bump the version number in your code. Then in setup(), if the code's number doesn't match the EEPROM's number, you know that you should go ahead and initialize any other important EEPROM state. Write the code's schema to EEPROM at that time, so the next run will match and you won't wipe out your progress.

// change this to any new value to re-init EEPROM state
#define SCHEMA 0x0101

void setup()
{
    short schema;
    EEPROM_readAnything(0, schema);
    if (schema != SCHEMA) {
        reinitialize();
        schema = SCHEMA;
        EEPROM_writeAnything(0, schema);
    }
}

void reinitialize()
{
    //TODO: assume EEPROM contents are invalid, rewrite initial values
}

For the readAnything/writeAnything functions I mention here, see my article: Arduino Playground - HomePage

A second note on your plans: EEPROM has a limited number of write cycles before the physical EEPROM parts wear out. It's like bending a paper clip, at some point the metal will fatigue and break.

If you're writing something a few times per hour, whenever battery power is connected, then you probably won't experience this problem. The chip is rated for about 100000 writes at any given location before it starts to fail.

If you're incrementing the same location multiple times a second, and connecting the device to a permanent source of power, then you'll start getting incorrect results because the EEPROM location has worn out from too much writing. The only fix is to replace the whole microcontroller chip and start the sketch from the beginning.

all right great, i believe you guys have answered my question.

Since I know i'll only need one spot in EEPROM to use, I just need one sketch to simply do
EEPROM.write(0,0);

and then in the sketch for my program, ill have something like the following
short value = EEPROM.read(0);
value++;
EEPROM.write(0,value);

This way, before the program is ever run, I know for certain that the value there is set to 0.