Hello to all.
I am trying write values greater than 255 with EEPROM.put function and read with EEPROM.get .
The problem is reading the values...
Here is my code
#include <EEPROM.h>
int values [5] = {300,400,500,600,700};
int read_cnt = 0, write_cnt = 0,readed_value = 0;
void setup(){
Serial.begin(9600);
for(write_cnt = 0; write_cnt <=4; write_cnt++)
EEPROM.put(write_cnt,values[write_cnt]);
for(read_cnt = 0; read_cnt <=4; read_cnt++)
{
EEPROM.get(read_cnt,readed_value);
Serial.println(readed_value);
}
}
void loop(){
}
The expected values on serial monitor are 300,400,500,600,700 but I got -28628, -2928, 22772, -17320, 700 .
What must I do ? Can anyone help me ?
system
2
What must I do ?
Understand what types you can store in EEPROM (Hint: Not int) and how to store other types there.
Yeah I got it and changed int values to float.
But the result is the same.
The last written value is true, but the previous ones are wrong.
#include <EEPROM.h>
float val1 = 500.0;
float val2 = 600.0;
float val3 = 700.0;
float read1=0.0;
float read2=0.0;
float read3=0.0;
void setup() {
Serial.begin(9600);
EEPROM.put(0,val1);
EEPROM.put(1,val2);
EEPROM.put(2,val3);
EEPROM.get(0,read1);
EEPROM.get(1,read2);
EEPROM.get(2,read3);
Serial.println(read1);
Serial.println(read2);
Serial.println(read3);
}
With this code I got 0.0 - 0.0 - 700.0 ....
After searches I got the point.
Floats are 4 bytes long so I have to write datas to EEPROM with 4 bytes (adresses) blocks.
Like;
EEPROM.put(0,val1);
EEPROM.put(5,val2);
EEPROM.put(9,val3);
EEPROM.get(0,read1);
EEPROM.get(5,read2);
EEPROM.get(9,read3);
Thanks bro....