I want write some bytes to the EEPROM. I read the API documentation (http://arduino.cc/en/Reference/EEPROMWrite). The write() function returns void (first suggestion: the function description should have the function signature) nut the documentation alerts that “The EEPROM memory has a specified life of 100,000 write/erase cycles”. So I suppose that the write process can fail after a significant numbers of write/erase cycles.
Did it mean that I must always test if the byte was effectively written in the EEPROM? How can I do this? Should I read every byte after a write and test if the read byte is equal the written one? (second suggestion: the function write() should return bool).
Note: I found the EEPROMEx library (playground.arduino.cc/Code/EEPROMex). The EEPROMClassEx::write() method returns bool. But the EEPROMClassEx::isWriteOk() is just too naïve (a constructive criticism).
Did it mean that I must always test if the byte was effectively written in the EEPROM?
No it means design your system in such a way that you will never exceed the limits.
Should I read every byte after a write and test if the read byte is equal the written one?
You can if you want.
: the function write() should return bool
That will have to do the same thing and slow down access for the majority of people who don’t need this.
As the source code is available you can always write your own function to check for you if you think you need it. EEPROM memory is comparatively slow you know.
Read it after writing.
Reading it is a lot faster than writing, so it is only a little overhead.
And reading it does not influence the 100.000 times.
You can rely on the 100.000 times and you should write your code in way that it does not get near it.
Normally there is not need to check it, or your code should reduce the number of writes.
There is more to this:
You can use the whole EEPROM and use every location to spread the writes. The 100.000 is for each single byte.
When a byte is no more reliable, it might fail after the check. So you can never be sure. The normal way to solve this, is with two sets of data with checksum. If one failes, use the other. If the other fails, use the default from flash (code in the sketch).
What if the Arduino looses power when writing ? So even with a good EEPROM there still might be invalid data. You need something as backup anyway.
While I was writing this, Grumpy_Mike wrote the same (improve your sketch).