EEPROMWriteAnything not working

Hi,

I want to use the EEPROMWriteAnything code to store some persistent data for the following sketch:

http://www.julietmikebravo.nl/static/div/inkubator.txt

I have defined a struct as follows:

struct config_t{
float thermoC_d ;
float thermoC_n ;
boolean night ;
boolean night_timer ;
byte bgn_night ;
byte end_night ;
}configuration;

When I run the sketch the eeprom write and read function report that 12 bytes have been written or read from eeprom, but the variables are not updated.

Is there some mistake in my code or is there some conflict?

Have you tried using the example code and writing the values seperately?

I have only ever used it for a single floating point variable on 0 onwards.

Mowcius

TNW–

The EEPROM functions are working fine. They read and write your “configuration” structure just fine. The problem is that you are not using the members of that structure in your program. You are using identically named global variables.

To correct this, remove the global variables (where you write “various variables”) and use the structure members instead.

For example, instead of

thermoC = thermoC_d;

you’d write

thermoC = configuration.thermoC_d;

Mikal

Thanks Mikalhart, I will try it as soon as I have my stuff in a housing and functioning again :)

Well, it's working except the program is now running with bad data read from the eeprom.

How can I initialize the struct with proper, within-range values?

I am thinking of checking for proper values in void setup() and filling in default values if the detected values are out of range. Is that the proper way of doing stuff like this?

Implemented default values in setup:

EEPROM_readAnything(0, cfg); //read values from eeprom
  if (cfg.thermoC_d > 50.0 && cfg.thermoC_d < 20.0){      // check for proper in range values,
    cfg.thermoC_d = 27.5;        // correct if needed
  }
  if (cfg.thermoC_n > 50.0 && cfg.thermoC_n < 10.0){
    cfg.thermoC_n = 22.5;
  }
  if (cfg.bgn_night > 23){
    cfg.bgn_night = 23;
  }
  if (cfg.end_night > 23){
    cfg.end_night = 7;
  }

Also got some weird behavior of variables in the structure.
I first had the floats first in the struct but for some reason I couldn’t change the thermostat temps in my menu.
Moved the floats to the end of the struct and everything works fine… :-?

Glad it's working, I think it is a relatively unused tool so there will still be some bugs to iron out in it...

Most people are inclined to use SD cards now, including me most of the time!

Mowcius

I don’t think anything is wrong with Halley’s brilliant little concoction. The reason it seemed to read strange values from the EEPROM was probably because the original (buggy) version of the code wrote them there. It was after all writing a structure which was not being used.

Mikal

  if (cfg.thermoC_d > 50.0 && cfg.thermoC_d < 20.0){      // check for proper in range values,
    cfg.thermoC_d = 27.5;        // correct if needed
  }
  if (cfg.thermoC_n > 50.0 && cfg.thermoC_n < 10.0){
    cfg.thermoC_n = 22.5;
  }
  if (cfg.bgn_night > 23){
    cfg.bgn_night = 23;

This code is saying: if a number is more than 50 and less than 20, do something. I can’t think of any numbers that are more than 50 and less than 20.

Perhaps you meant to say:

  if (cfg.thermoC_d > 50.0 || cfg.thermoC_d < 20.0){      // check for proper in range values,
    cfg.thermoC_d = 27.5;        // correct if needed
  }
  if (cfg.thermoC_n > 50.0 || cfg.thermoC_n < 10.0){
    cfg.thermoC_n = 22.5;
  }
  if (cfg.bgn_night > 23){
    cfg.bgn_night = 23;

Which is saying, if the number is more than 50 OR the number is less than 20.

Regards,

-Mike

Thanks for the suggested correction of my code.

It still seems that there is some issue with reading certain types of data from eeprom using WriteAnything.

The boolean "night" when set in the menu is not properly recalled when I exit the menu. When I re-enter the menu it is always set to false. When I moved variables around in the struct it was working, but the night and day thermostat temperatures were stuck and could not be changed...

I'm guessing EEPROMWriteAnything is not completely bug-free. Of course it could also be my code, over 16K for a glorified thermostat ::)