Go Down

Topic: EEPROM reading values problem[SOLVED]!! (Read 1 time) previous topic - next topic

sirus

Well!!The description of my problem has to do that i've got multiple analog inputs(how to do that?With one potensionmeter on the input)
Then i'm trying to collect the first 10 values( thats for start, the next step is to do something like that in every 10 minutes) and then i should read these 10 values in eeprom.

After that, i should sent a command from a usb interface application which i've done, to preview this 10 values.

Thanks a lot!!!

PaulS

It is not clear why you need to use EEPROM at all. Start with that. Why do you need to persist sensor data across resets?

sirus

PaulS thank you my friend for you advice!If the project belogs to me, there would be no problem about it!They demand from me to use eeprom...I don't know why!!!All the internet is full with source code and ideas about storage read and writing in other external storage types like,SD,USB etc...

Take it to the other side that it's something like school homework.In this case, you can't say something to your teacher!!!Thats my side now my friend if you could understand me!!!


Thanks again for all!I'll appreciate if you could help a newbie like me!!!  :smiley-mr-green: ;)

Grumpy_Mike

When you do:-
Code: [Select]
EEPROM.write(cData, sensorValue);
You only write one byte of data.
When you do:-
Code: [Select]
sensorValue = analogRead(analogInPin);
You create a variable that takes up 2 bytes of data. In order to write that value you need to split it up into two parts
Code: [Select]
EEPROM.write(cData, sensorValue & 0xff);
EEPROM.write(cData+1, sensorValue >> 8);

When you increment cData you need to do it by two because each value you put into EEPROM takes up two bytes.
Code: [Select]

// not cData++; but
cData+=2;


So you also need to do this when reading:-
Code: [Select]
value = EEPROM.read( addr  ) + (EEPROM.read( addr+1 ) << 8);
and again increment by 2
Code: [Select]

// not cData++; but
cData+=2;


At the start of your loop() put
Quote

if(cData >= 20) cData = 0; // keeps the value under 10 values




sirus

Thanks a lot!But could you explain me the last line please???I don't understand it .... :smiley-mr-green:

Thanks again!

Go Up