Hello,
I am using an Arduino Uno Rev R 3 by Wavgat.
Initially, I tested all functions never powering off the board and they worked. Then, when I turned off the board, I noticed that the EEPROM never stored any data at any address.
For example, I cut and pasted from examples I read on this forum the simple code below that writes a a float (I assigned the 35.00 to the float variable) and I used EEPROM.write() to store this number, starting from address 0 when buttonPin is high.
Then, function EEPROM.get() retrieves the stored value and displays it in serial monitor.
If I never turn off the board I see EEPROM.get() working perfectly.
If I power off the board, turn off a switch that causes buttonPin to become low so the EEPROM.write() code is bypassed, EEPROM.get() return 0.00 value as nothing was stored.
i obviously used also EEPROM.put() and nothing changes.
Am I am doing anything wrong?
Am I using a poor quality board simulating an EEPROM with a volatile memory ?
Is there any special setting in some configuration file I must customize to permanently store data in EEPROM?
Below, the test code compiled with Arduino 1.8.19 hourly build (other builds behaved equally to this):
//Test EEPROM
#include<EEPROM.h>
float y =00.00;
int pressButton=0;
void setup() {
Serial.begin(9600);
float x = 35.00;
const int buttonPin=3;
pinMode(buttonPin, INPUT);
delay(50);
pressButton=digitalRead(buttonPin);
if(pressButton==HIGH){
Serial.println(pressButton);
byte ptr;
ptr = (byte)&x; //ptr holds beginning address of 4-byte memory space containing value of x
for (int i = 0, address = 0; i < 4; i++, address++, ptr++)
{
EEPROM.write(address, *ptr);
delay(50);
}
}
}
void loop() {
y=(EEPROM.get(0,y));
Serial.println(y);
delay(1000);
}