Pages: [1]   Go Down
Author Topic: EEprom storage using writeAnything.h  (Read 1800 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

mySensVals   will be numbers anywhere from 100 to 2000
Does the Uno have enough eeprom to store this many settings?
thanks.

Code:
struct config_settings
{
    int mySensVals[12];  //# of pulses in 2-12 cups
    boolean Enable_Audio;  //whether the user wants sound
    boolean Enable_Piezo;  //whether the user wants a knock sensor
    boolean Enable_PhotoCell;  //whether the user wants to use the photocell
} MySettings;


//...set up values to save. 

    EEPROM_writeAnything(0, MySettings);  //save the settings
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I count 27 bytes of storage needed to store that structure into eeprom. As the Uno has a 1,000 byte eeprom it should fit rather nicely, if not lonely with all the extra eeprom space avalible.  smiley-wink

Lefty
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks! (that was quick).  I'll reread the ref section on sizes, an integer must be only 2 bytes, and a boolean 1, to only add up to 27...
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, I just read the size of bolleans and integers.  strange a boolean only holds true or false, in 1 byte, and and integer at 2 bytes can hold a huge number.  I thought it would have been a lot more bytes than that.  I should be okay with all the settings I can think of changing!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 303
Posts: 26354
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
strange a boolean only holds true or false, in 1 byte, and and integer at 2 bytes can hold a huge number.
The smallest addressible item on the AVR is a byte.
If you are really pushed for space (it doesn't look like you are!), you can use structs with bit-fields defined in them for boolean flags.
Code:
struct {
unsigned flag0:1; // defines eight, one bit fields.
unsigned flag1:1;
unsigned flag2:1;
unsigned flag3:1;
unsigned flag4:1;
unsigned flag5:1;
unsigned flag6:1;
unsigned flag7:1;};
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
struct config_settings {
    int mySensVals[13];  //# of pulses in 2-12 cups
    int motor_delay;     //change the distance the platform travels
    boolean Enable_Audio;  //whether the user wants sound
    boolean Enable_Piezo;  //whether the user wants a knock sensor
    boolean Enable_Photocell;  //whether the user wants to use the photocell to turn on the cabinet lighting
    int Photocell_Level;  //threshold for light/darkness
} MySettings;

void LoadSettings(){
  EEPROM_readAnything(0, MySettings);   //load the settings
}

void SaveSettings(){
  EEPROM_writeAnything(0, MySettings);  //save the settings
  sendMessage("Settings saved!");
}

...so I think I'm using 33 bytes of EEPROM to save settings.
Now I have other settings I want to save/load in reference to time, since I've added an RTC module.
Can I save other settings to another part of the EEPROM like this:
Code:
struct config_settings {
    int CurrentYear;    //for keeping track of what year it is
    int CupsTotal;    //lifetime total
    int CupsMonth;    //cups drank this month
    int CusYear;        //cups drank this year
    int CupsLast;    //last cup drank
} TimeData;

void LoadSettings(){
  EEPROM_readAnything(34, TimeData);   //load the settings
}

void SaveSettings(){
  EEPROM_writeAnything(34, TimeData);  //save the settings
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can I save other settings to another part of the EEPROM like this:
Yes, and no. You have the right idea, and address, but this:
Code:
struct config_settings {
    int CurrentYear;    //for keeping track of what year it is
    int CupsTotal;    //lifetime total
    int CupsMonth;    //cups drank this month
    int CusYear;        //cups drank this year
    int CupsLast;    //last cup drank
} TimeData;
won't work, because you have already defined a struct called config_settings, so you can't define another struct with the same name.

Code:
    int CusYear;        //cups drank this year
CusYear? No p?
Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 655
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    int CusYear;        //cups drank this year
CusYear? No p?

Ok, maybe it'd be better with a p.
 smiley-red

Thanks, I didn't think about the first part of that struct, since I never use the name 'config_settings', I thought it was just part of the code that made the whole thing work.  So it can be anything?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 617
Posts: 49463
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So it can be anything?
Well, there are a few reserved keywords that it CAN'T be, but everything else is what it CAN be.
Logged

Pages: [1]   Go Up
Jump to: