So I don't know what gives here. I've been banging my head against a wall trying to figure out why my code does not write floats properly to EEPROM of my arduino UNO. Rather, it will write one value at the end of a for loop and all other values come out as garbage or negative values, or "-0.00"?
#include "Arduino.h"
#include <EEPROM.h>
int eLocation = 0;
float ePutValue = 01.45;
float eGetValue;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("");
Serial.println("");
Serial.println("---------STARTING-----------");
//to do the get method--->EEPROM.get(address, data)
Serial.println("Last Value Known:");
EEPROM.get(eLocation, eGetValue);
Serial.println(eGetValue, 2);
Serial.println("");
Serial.println("");
// get values in a for loop
for (int i = 1; i < 5; i++) {
Serial.println("Loop Value:");
EEPROM.get(eLocation, eGetValue);
Serial.println(eGetValue, 2);
eLocation = eLocation + 1;
Serial.println("");
delay(200);
}
Serial.println("");
Serial.println("");
Serial.println("***********Writing*************");
//write values in a for loop
for (int i = 1; i < 5; i++) {
Serial.println("Write Value:");
//delay(500); //pause at least 3.3ms to write data.
//One simple call for put, with the address first and the object second.
EEPROM.put(i, ePutValue);
Serial.println(ePutValue);
Serial.println("To address:");
Serial.println(i);
Serial.println("");
delay(500);
ePutValue = ePutValue + 1.12;
}
Serial.println("");
Serial.println("");
Serial.println("**************Final Readout***************:");
for (int i = 0; i < 5; i++) {
Serial.println("get method:");
EEPROM.get(i, eGetValue);
Serial.println(eGetValue);
Serial.println("");
}
} //end setup()
void loop() {
// put your main code here, to run repeatedly:
}
The final readout values are all -0.00 except for the last one, which is 1.45(which is correct).
Can anyone tell me what I'm doing wrong? Why is only the last value being correctly written here? Upon resetting and checking the serial monitor, none of the correct values are being returned from EEPROM. I'm probably missing something basic. HELP!
-dan