I'm not sure what you mean... this works for me
#include <EEPROM.h>
// __attribute__ ((packed)) is to force the compiler to use the minimum required memory to represent the type
// see https://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Type-Attributes.html
struct __attribute__ ((packed)) _paramS {
unsigned long t1ontimeDAY;
unsigned long t1offtimeDAY;
unsigned long t2ontimeDAY;
unsigned long t2offtimeDAY;
unsigned long t3ontimeDAY;
unsigned long t3offtimeDAY;
unsigned long t1ontimeNIGHT;
unsigned long t1offtimeNIGHT;
unsigned long t2ontimeNIGHT;
unsigned long t2offtimeNIGHT;
unsigned long t3ontimeNIGHT;
unsigned long t3offtimeNIGHT;
} myParamters;
const uint32_t keyword = 0xBADCAFFE;
const uint16_t keywordAddress = 0x00;
const uint16_t paramAddress = keywordAddress + sizeof(keyword);
void printParam()
{
Serial.println(F("\n************* PARAMS *************"));
Serial.println(myParamters.t1ontimeDAY);
Serial.println(myParamters.t1offtimeDAY);
Serial.println(myParamters.t2ontimeDAY);
Serial.println(myParamters.t2offtimeDAY);
Serial.println(myParamters.t3ontimeDAY);
Serial.println(myParamters.t3offtimeDAY);
Serial.println(myParamters.t1ontimeNIGHT);
Serial.println(myParamters.t1offtimeNIGHT);
Serial.println(myParamters.t2ontimeNIGHT);
Serial.println(myParamters.t2offtimeNIGHT);
Serial.println(myParamters.t3ontimeNIGHT);
Serial.println(myParamters.t3offtimeNIGHT);
}
void saveParam()
{
EEPROM.put(keywordAddress, keyword);
EEPROM.put(paramAddress, myParamters);
}
void getParam()
{
uint32_t tmpKey;
EEPROM.get(keywordAddress, tmpKey);
if (tmpKey == keyword) {
EEPROM.get(paramAddress, myParamters); // EEPROM was already initialized OK to read
} else {
// First run on this arduino, memory was never initialized. so establish default values
myParamters.t1ontimeDAY = 1;
myParamters.t1offtimeDAY = 2;
myParamters.t2ontimeDAY = 3;
myParamters.t2offtimeDAY = 4;
myParamters.t3ontimeDAY = 5;
myParamters.t3offtimeDAY = 6;
myParamters.t1ontimeNIGHT = 7;
myParamters.t1offtimeNIGHT = 8;
myParamters.t2ontimeNIGHT = 9;
myParamters.t2offtimeNIGHT = 10;
myParamters.t3ontimeNIGHT = 11;
myParamters.t3offtimeNIGHT = 12;
saveParam();
}
}
void setup() {
Serial.begin(115200);
getParam(); // first run will establish the defaults in EEPROM
printParam(); // see what the values are
myParamters.t1ontimeDAY = 10;
myParamters.t1offtimeDAY = 20;
myParamters.t2ontimeDAY = 30;
saveParam(); // save it
printParam(); // show it has been saved
}
void loop() {}
this is what I see in the console (set at 115200 - there is NO reason to go slow at 9600 bauds)
[sub][color=purple]
************* PARAMS *************
[color=green]1
2
3[/color]
4
5
6
7
8
9
10
11
12
************* PARAMS *************
[color=red]10
20
30[/color]
4
5
6
7
8
9
10
11
12
[/color][/sub]
the initial values are set properly and the 3 I changed are correctly changed...
If I run the code a second time, this is what the console shows
[sub][color=purple]
************* PARAMS *************
[color=blue]10
20
30[/color]
4
5
6
7
8
9
10
11
12
************* PARAMS *************
10
20
30
4
5
6
7
8
9
10
11
12
[/color][/sub]
we can see that the first read of the data in memory noticed that memory was already initialized and thus read the 10, 20 and 30 I had written there previously
Note that I changed the keyword so that your Arduino understands not using the previous values