Splittin and storing multiple data into EEPROM, then reading them as one

Hi
I'm new to Arduino and i have a problem i have been trying to solve but couldn't figure a way out. Basically i have a set of different datas i want to send to Arduino and each set contains a 6 digit number that goes like 105268, 152368 and so on. What i want to do is, to store these values into EEPROM after some certain conditions were met for once and then i want to read these values to run my code. To clarify it, let's say i want to press a button for 2 seconds and when that's done, send one of those datas (e.g 105268) and store the value into EEPROM. So after i shut down arduino and restart it the value will remain there and will be read to check if the data i sent match the stored one. If yes then run the code. Certainly the second time i send the same data i want it to run without me having to press the button for 2 seconds and store the data again. My approach so far goes like this. Let's say i sent the data 105268 after 2 seconds button press. I will run a code that goes like;

data = receivedValue; //The received value here is the signal data 105268
EEPROM.write(0, data/10000); // save the first two digits into address 0
EEPROM.write(1, (data/100)%100)) // save the next two digits into address 1
EEPROM.write(2, data %100); //save the last two digits into address 2

This is my approach for saving the value into different addresses. But i'm not sure how i'm gonna read them as one to match the original data. Reading from multiple addresses and joining them together. When that is achieved, and datas are matched i want it to run my code. After that i want to send another data (e.g 152368) and store it into different addresses (like address 3, 4, 5). So i will have 2 different data stored in the EEPROM and when the program restarts both signals will work without a problem, as the EEPROM.read will check the values and see if they match. And i want to go on like that, and store as much data as i can. I know EEPROM limit is 512 bytes, which is already plenty for me. Therefore this is my problem and i'm stuck, so i would appreciate any help i can get. :slight_smile:

Why mess about saving the data byte by byte when you can save a variable of any size using EEPROM.put() and retrieve it again using EEPROM.get() using a single command in each case ?

Thanks for the reply! I didn't know i could do that. Can you give me an example on how i could use them here, if it is not too much of a hassle for you? Because i'm a complete newbie :slight_smile:

EEPROM reference.

Thanks guys. That information proved useful indeed. However this time unless i use the EEPROM.put function in void loop section, i can't seem to store the data. I send the signal data by a remote switch, and when i try to store it in void setup section, EEPROM.get only returns the value "0". When i use it in void loop however, i get the desired value. But if i use it in void loop, the EEPROM will wear out in no time and i want to avoid that. So i'm wondering if i use the condition in void loop section and only after the condition was set make it run the EEPROM.put command (e.g if button is pressed for 2 seconds run EEPROM.put command), will i avoid wearing the EEPROM out?

Or a condition in loop that only saves the value to EEPROM if the value has changed.

when i try to store it in void setup section, EEPROM.get only returns the value "0".

Post the program that shows this happening

Thanks again. I have solved the problem. Sorry for the late reply :slight_smile:

I have solved the problem. Sorry for the late reply

Perhaps you could share your solution so others may benefit?

Ah sure, my bad. As i mentioned earlier i set a condition in void loop in which when i press the button for two seconds and release it, it turns on a led. When the led is on i send the data through the remote control and write it to EEPROM and reset the button timer so that i can turn the led off to avoid wearing down EEPROM.