The following code should read in each of the first 32 bytes of EEPROM, increment the value found at each location, and write out that incremented value. That is, each time the code runs, it ought to increase the values it prints out by 1. Instead, it’s increasing them by 2! I’m stumped, and hoping someone will spot some obvious error:
#include <EEPROM.h>
void setup() {
Serial.begin(115200);
while (!Serial);
EEPROM.init();
for (uint8_t i = 0; i < 32; i++) {
uint8_t val = EEPROM.read(i);
Serial.print(val);
Serial.print("->");
EEPROM.write(i, val+1);
Serial.print(EEPROM.read(i));
Serial.print(" ");
}
Serial.println("");
}
void loop() {
}
Two consecutive sample outputs:
0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 [...]
2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 [...]
Where I’d expect the second output to be:
1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 [...]
just tried your sketch on V2.2.1 on an Artemis ATP, works as expected :
->255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0 255->0
-> 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1 0->1
-> 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2 1->2
-> 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3 2->3
Maybe re-install the library ?
Maybe reset is pushed twice / bouncing?
It was bouncing. I am dumb. 
I got lazy and was just unplugging and plugging in the board, instead of implementing a clean reset mechanism. Added a proper reset circuit and now everything is working.
Thank you!
1 Like