EEPROM.put() get() in FOR

hi guys need help tring an easy one but cant make it to work
im want to write to eeprom - 3 array[x] one is unsigned long two is int
i dontknow whats the the contect

i tried to make a two for loop

//address will change with +50  from other funcation 

       EEPROM.put(address, GetData);
       EEPROM.put((address+10), GetDData);
       EEPROM.put((address+20), GetPData);

for (int i=0 ; i<250; i=i+50 ) {  
    for (int z = 0 ; z<5 ; z=z+1 ){
      EEPROM.get( i , 
       EEPROM.put(address, GetData[z] );
      EEPROM.get(( i+10 ), GetDData[z] );
      EEPROM.get(( i+20 ), GetPData[z] );
    }
  }

when i read it manualy its working

EEPROM.get( 0, data1[z] ); "
 EEPROM.get( 10, data2[z] ); "
 EEPROM.get( 20, data3[z] ); "

plz help

Welcome to the forum

Please post a complete sketch that illustrates what you are trying to do

 EEPROM.get( i , 

What is this intended to do ?

That is a rather convoluted function call. EEPROM.put(addreee, GetData[z]) will write the value in GetData[z] to EEPROM, then return a reference to GetData[z]. The value read from EEPROM address i is then written to GetData[z]. This is assuming the compile does everything in that assumed order.

The put() and get() functions will work with entire arrays, then is no need to write / read each individual element of the array.

first ' thank you :slight_smile:

about the code i can post the full code but i can tell you

its waiting for 3 input each time in a loop for 5 times
so in the end i got
5 groups of 3 inputs

i want to save them and pull the data after

i trying to make it shorter by 2 for loop


    EEPROM.get(0,Data[1]);
    EEPROM.get(10,DataX[1]);
    EEPROM.get(20,DataXX[1]);

      EEPROM.get(100,Data[2]);
      EEPROM.get(110,DataX[2]);
      EEPROM.get(120,DataXX[2]);

      EEPROM.get(200,Data[3]);
      EEPROM.get(210,DataX[3]);
      EEPROM.get(220,DataXX[3]);

      EEPROM.get(300,Data[4]);
      EEPROM.get(310,DataX[4]);
      EEPROM.get(320,DataXX[4]);

    EEPROM.get(400,Data[5]);
    EEPROM.get(410,DataX[5]);
    EEPROM.get(420,DataXX[5]);

As has previously been pointed out, you can put() and get() whole arrays with single commands so why use 15 calls to get() when you could use just 3 ?

sorry but i don't understand how .. its 15 different veribels

But only 3 different arrays. As long as you make sure that the difference between the EEPROM addresses is large enough to hold the number of bytes in each array so that they do not overlap you can save and load whole arrays like this

EEPROM.put(0, Data);      //save Data array at 0
EEPROM.put(100, DataX);   //save DataX array at 100
EEPROM.put(200, DataXX);  //save DataXX array at 200

EEPROM.get(0, Data);      //load Data array from 0
EEPROM.get(100, DataX);   //load DataX array from 100
EEPROM.get(200, DataXX);  //load DataXX array from 200

NOTE that I have deliberately allowed masses of space for each array by using addresses 0, 100 and 200

oh but data[0] != data[1] != data[2] != data[3] != data[4]
what if i only need data[4] ? or dataXX[3] ?

Just get() the whole array then use the single value from the array in the sketch

Similarly if you change a single value in the array and want to save it just put() the whole array. Any values that have not changed will automatically not be written again. There is also an update() function that does the same thing but the name is more explicit

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.