# not understanding how EEPROM write works in arduino

I saw the following in the arduino-examples section but i am not understanding why the analog input is being divided by 4. if e.g the input value is 1023 then it will require 2 bytes to store since 1023 is 3FF hex. but if i divide it by 4 then i am not storing the original value rather the divided value . can someone explain how i can save the input analog values to EEPROM ?

thanks

void loop() { // need to divide by 4 because analog inputs range from // 0 to 1023 and each byte of the EEPROM can only hold a // value from 0 to 255. int val = analogRead(0) / 4; // write the value to the appropriate byte of the EEPROM. // these values will remain there when the board is // turned off. EEPROM.write(addr, val); // advance to the next address. there are 512 bytes in // the EEPROM, so go back to 0 when we hit 512. addr = addr + 1; if (addr == 512) addr = 0; delay(100);

Look in the reference for the functions highByte() and lowByte. You have an analog reading named int input. EEPROM.write(address, highByte(input)); EEPROM.write( address + 1, 1owByte(input));

There is also a library to help with writing arbitrary values into EEPROM, called EEPROMWriteAnything

be aware that writing to EEPROM is limited - OK 100,000 times is still a lot - but in a tight loop the counter adds quickly..

some tips: - spread the readings over the EEPROM (use all addresses, add a time stamp to find last one) - use compression e.g run length + noise removal - use an external EEPROM that can be replaced

how many bytes is available to me for EEPROM and from which address ?
I have to basiscally store the following info:

• date in format mm/dd/yyyy
• time1 in format hh:mi:ss
• time2 in format hh:mi
• time3 in format hh:mi
• time4 in format hh:mi
• integer 1 < 100
• integer 2 < 100

regards

how many bytes is available to me for EEPROM and from which address ?

It depends on the processor type, and zero.

Uno - 1024 bytes
Mega2560 - 4096 bytes
'1284P - 4096 bytes

Looks like you need 15 bytes.