Using precisely this code - the eeprom_put example in the Arduino IDE, and am seeing some strange results...
The sketch does write correctly to eeAddress = 0, and the corresponding eeprom_get sketch does return the data.
Please note that I've initialized the entire EEPROM with 'FF's before any test...
The weird part is this sketch writes exactly the same data starting at Address = 2048. The loop is not running; I see no jump to offset 2048... I gotta be missing something!
I'm dumping EEPROM using avrdude, and viewing results in an external hex editor.
How is this stuff stored? Apart from not being able to directly view a float - OK, I get it - should the other data be simply viewable in hex?
My own experiments in writing hex bytes directly also work, but also write in two locations.
Small update to this: Precisely the same behavior seen with a RobotDyn Mega. Both the 'clone' Mega and the RobotDyn report: Device signature = 0x1e9801 (probably m2560)
#include <EEPROM.h>
struct MyObject {
float field1;
byte field2;
char name[10];
};
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
float f = 123.456f; //Variable to store in EEPROM.
int eeAddress = 0; //Location we want the data to be put.
//One simple call, with the address first and the object second.
EEPROM.put(eeAddress, f);
Serial.println("Written float data type!");
/** Put is designed for use with custom structures also. **/
//Data to store.
MyObject customVar = {
3.14f,
65,
"Working!"
};
eeAddress += sizeof(float); //Move address to the next byte after float 'f'.
EEPROM.put(eeAddress, customVar);
Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
}
void loop() {
/* Empty loop */
}