Write anything to EEPROM

Hello everyone

I ran into spacing issues with my program that I'm currently busy with (Arduino UNO, 32 KB of memory). The culprits are the strings that I'm implementing. I did a rough calculation and I can free up round about 500 Bytes of information if I could move the strings from the flash memory to the EEPROM i.e. out of my program memory. From what I read it seems that I should turn it into a lookup table. I understand this by writing it into a array and then reading it from the array from EEPROM.

The strings will be constant variables that I only want to read from the EEPROM to be able to print on a GLCD screen. I am unsure if I load the strings whether it will add to the flash memory or to the SRAM memory (When I load it out of the EEPROM)? Or should I specify in which memory type / location it must be loaded into?

I also have some other integer values that I need to store into my EEPROM. I've loaded all these values into an integer array and have used the "Write anything to EEPROM" library to accomplish this:

http://playground.arduino.cc/Code/EEPROMWriteAnything#.U0G6UqiSxoM

This is working wonderfully. But now, the second question, how can I write both these arrays together into one array and then into the EEPROM memory or should I write both arrays separately into the EEPROM memory? I also looked around on the forum and somewhere it was mentioned that the Write anything to EEPROM library doesn't work very well for strings, but I'm not sure whether that is the case if you want access to a specific part of a string or to a constant string as in my case?

Below is an example of the strings that I wish to write to EEPROM as well as an example of the values I will be inserting into the integer array. The integer array have been predefined here for explanation sake. In my program I define it but I don't populate the array (Happens through the program)

//***********************************************************************************

char* String_Lookup_Table_Array[] = 
{
  "MENU:",                              // String 1
  "ESC",                                // String 2
  "ENT",                                // String 3
  "PREH Hysteresis:",                   // String 4
  "HEAT Hysteresis:",                   // String 5
  "SLDR Hysteresis:",                   // String 6
  "   EDIT PARAMATERS  ",               // String 7
  "     VIEW PROGRAM    ",              // String 8
  "     RUN PROGRAM    ",               // String 9
  "   STORE VARIABLES  ",               // String 10
  "EDIT PARAMATERS:",                   // String 11 
  "   EDIT PROGRAM   ",                 // String 12
  "   EDIT HYSTERESIS  ",               // String 13
  "   EDIT FAN STATUS  ",               // String 14
  "Fan Status:",                        // String 15
  "OFF",                                // String 16
  " ON",                                // String 17
  "STORING VARIABLES",                  // String 18
  "TO EEPROM"                           // String 19
};

//***********************************************************************************

int Stored_Values [12] = 
{
150,                                    // PREH
180,                                    // HEAT
210,                                    // SLDR
180,                                    // KEEP
150,                                    // COOL
5,                                      // PREH_Hysteresis
5,                                      // HEAT_Hysteresis
10,                                     // SLDR_Hysteresis
1                                       // FAN_Status
};

//***********************************************************************************

if I could move the strings from the flash memory to the EEPROM i.e. out of my program memory.

You can't use strings that are stored in EEPROM. You need to read them into SRAM before you can use them. Will that really save you code space or SRAM?

This is working wonderfully. But now, the second question, how can I write both these arrays together into one array

Of what type? ALL the elements of an array MUST be the same type.

Hello PaulS

Thanks for the feedback. If I store the strings in the EEPROM I will save program memory. I am pretty sure that I will have enough SRAM for the program to run and execute correctly.

I miss quoted myself regarding storing both arrays into another array. If I wanted to accomplish something like that I would have to write it into a structure correct?

What I meant to say is that I will first have to write the string array to EEPROM and then I will have to write the integer array to the EEPROM memory where the integer array will be addressed after the string array in the EEPROM memory.

If I store the strings in the EEPROM I will save program memory.

I really can't see how. The strings will then be stored in program memory, SRAM, and EEPROM. Plus, you'll need to add code to get them from EEPROM. Unless there is something you are omitting, using EEPROM won't save program space.

What I meant to say is that I will first have to write the string array to EEPROM and then I will have to write the integer array to the EEPROM memory where the integer array will be addressed after the string array in the EEPROM memory.

The int array has a fixed length. The char array does not. Write the int array first.

I was thinking along the lines of creating a sketch with the necessary strings in and then to use this sketch to write the strings to my EEprom memory. Once done I would write my main program to the micro controller and then use this program, to load the strings from the eeprom into the SRAM memory where I will the be able to just print it in my main program by addressing the specific strings in the SRAM memory. So the strings itself are never saved inside the flash memory or the program memory but rather the address of each string of where to access it. Let me know if I’m not making sense or if you can’t do it like this.

Load Eeprom address 5-10 into SRAM address 10 - 15.
Glacd.print(SRAM address 10 - 15) in the flash memory or program memory

When using ATmel AVR programmers and programming software (and presumably others), it is possible to program EEProm directly using the programmer. That way the strings never reside in flash. I do not know how to define the hex file that would contain the strings, but that information is presumably available.

On the other hand, I don't see why your idea to write a separate program that just copies strings from program memory (flash) to EEprom would not work.

Before you resort to desperate measures like that, have you looked into how all that program memory is being used? There may be scope to reduce the size of your own code, and/or reduce the amount of library code that it requires.

jremington:
When using ATmel AVR programmers and programming software (and presumably others), it is possible to program EEProm directly using the programmer. That way the strings never reside in flash. I do not know how to define the hex file that would contain the strings, but that information is presumably available.

The Arduino IDE in fact produces the .eep file which is an Intel hex file that AVRDUDE can upload to EEPROM. I’m not aware that can be done from the IDE, or that the bootloader would handle it, but it could be done outside the IDE as a separate step with an ICSP.

Write your strings in chinese which can be encoded in fewer bytes.

Hello Everyone

Thanks for all the feedback, unfortunately I can't read Chinese so I think I might pass on that idea, but still a good solution though ;)

I've changed most of my integer variables that won't be larger than 255 to bytes and this have shaved 2 kB of memory of the total already. I want to add some additional functionality now but I'm not sure if the 2 kB will be enough memory for the functionality. I think that I will write the strings that I am using into an array and then call it from the array so that I'm not duplicating strings throughout the code. This should also save some additional space. If I then still don't have enough space then I will try and implement this lookup table solution. So I might ask some advise regarding the code in the future if I still don't have enough space for the added functionality.

Thanks again for all the input, much appreciated. Dirk