//Lets read the value back and print it to the serial value = EEPROM.read(address); //Output the data to serial Serial.print(value,DEC); // will print 123 Serial.print("\n"); //Serial.print(value,BIN); // will print 1111011 which is 123 in binary}

Now if I understand EEPROM right,if i was to reset the arduino at the "a" count of say...53, when it starts up again, it should pick up where it left off.instead it starts at 0 again.this is my first ever experience with EEPROM, so I would like to understand the basic of the code before I implement it in my other projects.cheers in advance for all your help guys.

The value that you are writing into EEPROM address #0 survives the reset but then when you power up again the first thing you do is overwrite with zero. You seem to be assuming that EEPROM gives you some kind of suspend/resume functionality when it does not - all it gives you is memory who's contents remain when the power is disconnected.

EEPROM is what is called non-volatile memory. Non-Volatile Memory, such as SD Cards, Hard Drives, and EEPROM, don't need a power source. The ATMega328's datasheet says it can store data for 100 years at room temp.!When you reset your arduino, the program starts over. All variable states are erased, leaving you ONLY with your bare program.If you want the arduino to pick up where it left off, write some simple code in the setup function that would set the variable a to the current value of address 0.

I would recommend reading a button or something to control when the writes happen so you don't just sit there & pound the living daylights out of that 1 location by accident, they do have limited durability. As pointed out, you start writing to address 0 whenever the sketch starts - maybe change the sketch to read first, with "a = EEPROM.read(address);", then continue incrementing "a" from there.Virgin EEPROM addresses will have 0xFF (255 decimal) when read back. Keep in mind that EEPROM.write has built in 3.3mS time to complete, which you provide for with 500mS delay. If you capture the time written as part of a loop of doing other stuff, and check that 3.3ms have gone by before starting the next write, you can be doing other stuff while waiting (this is the heart of Blink Without Delay).

I would recommend reading a button or something to control when the writes happen so you don't just sit there & pound the living daylights out of that 1 location by accident, they do have limited durability. As pointed out, you start writing to address 0 whenever the sketch starts - maybe change the sketch to read first, with "a = EEPROM.read(address);", then continue incrementing "a" from there.Virgin EEPROM addresses will have 0xFF (255 decimal) when read back. Keep in mind that EEPROM.write has built in 3.3mS time to complete, which you provide for with 500mS delay. If you capture the time written as part of a loop of doing other stuff, and check that 3.3ms have gone by before starting the next write, you can be doing other stuff while waiting (this is the heart of Blink Without Delay).

that was all I needed to do, the problem is solved thank you very much, and yes I will be using buttons to activate the code in other projectsAs just a little side note, thank you to the other two who also posted help and in refference to the second reply, pressding the reset button does not erase the EEPROM variables, they stay exactly the same.

for the benifit of others, here is the working code, I hope it helps in the future:

//Lets read the value back and print it to the serial value = EEPROM.read(address); //Output the data to serial Serial.print(value,DEC); // will print 123 Serial.print("\n"); //Serial.print(value,BIN); // will print 1111011 which is 123 in binary}

Bumping this thread 'cause I have a related question. I need to read and write several chunks of data from and to the EEPROM. I could fool around with structures and unions and cobble up something, but I found this code that does exactly what I want. Unfortunately, it doesn't work. When I paste it into my code the compiler barfs with bizarre errors in completely unrelated places. There appears to be something here that offends the C++ gods but such things are beyond me. Can anyone suggest a fix or some other source of code that does the same thing?

In file included from et218.cpp:50:/writeanything.h: In function 'int EEPROM_writeAnything(int, const T&)':writeanything.h:2: error: expected initializer before '*' tokenwriteanything.h:5: error: 'p' was not declared in this scope/writeanything.h: In function 'int EEPROM_readAnything(int, T&)':writeanything.h:11: error: 'byte' was not declared in this scopewriteanything.h:11: error: 'p' was not declared in this scopewriteanything.h:11: error: expected primary-expression before ')' tokenwriteanything.h:11: error: expected primary-expression before 'void'

In file included from et218.cpp:50:/writeanything.h: In function 'int EEPROM_writeAnything(int, const T&)':writeanything.h:2: error: expected initializer before '*' tokenwriteanything.h:5: error: 'p' was not declared in this scope/writeanything.h: In function 'int EEPROM_readAnything(int, T&)':writeanything.h:11: error: 'byte' was not declared in this scopewriteanything.h:11: error: 'p' was not declared in this scopewriteanything.h:11: error: expected primary-expression before ')' tokenwriteanything.h:11: error: expected primary-expression before 'void'

1. Move the #include <EEPROM.h> from the header file tab to the main sketch tab.2. Add 'typedef unsigned char byte;' to the top of the header tab where you had the #include that you just moved.

What you had before wasn't wrong, it's just that the Arduino IDE does some processing of your files during the build process that can break perfectly good code for no obvious reason.