The integers you want to store in eeprom need to be broken down into bytes to store them then when called from eeprom, recombined to make integers from them. Unless you are using a Due then integers are 4 bytes.
You can avoid the confusion and make it near seamless for the Due included by int16_t which makes your integers unsigned 16 bit integers.range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1) or us uint16_t which give you a range of 0 to 65,535 (2^16) - 1).
My code, alc is a 48 ellement array of 16 bit integers I am writing to EEprom for a preloader for an application
//… more code
for (int i = 0; i < 48; i++)
Serial.print(" ** Channel # “);
byte balc1 = (alc[i] & 0xFF);
byte balc2 = ((alc[i] >> 8) & 0xFF);
//Write the 2 bytes into the eeprom memory.
Serial.print("\t Address “);
Serial.print(i * 8);
EEPROM.write(i * 8, balc2);
EEPROM.write(i * 8 + 1, balc1);
////… more code
* *Then to read the code from EEprom I do the following to check that the numbers were written.* *
* for (int i = 0; i < 48; i++)
Serial.print("\n ** Channel # “);
//Read the 2 bytes from the eeprom memory low calibration data.
int16_t i16alc1 = EEPROM.read((i * 8));
int16_t i16alc2 = EEPROM.read((i * 8) + 1);
alcck[i] = ((i16alc2<<0)&0xFF)+((i16alc1<<8)&0xFFFF);
if (alcck[i] == alc[i])
Serial.print(" OK “);
Serial.print(” Bad ");
chkflag = 1;
… more code
I don’t know if I’m doing it right but I get expected results. This instance is running on a Nano.
My *8 or times 8 for my address is because I am writing and reading 4 16 byte integers on the same loop. It display the address and (i * 8 + 2) for memory location of my next array element and (i * 8 +4) for the next and (i * 8 +6) for the last. I running all this in the setup so it doesn’t loop. You have about 10,000 Writes to EEprom before it’s toast.