Resolved: avr/eeprom eeprom_write/read_block usage

Hi all,
Firstly, I am relatively new at this and especially new (read, never used) when it comes to pointers which I believe I may need to accomplish this task.

I'm planning to use a 16x2 LCD display to display over 40 different messages at one time or another and I'd like to get these message in EEPROM using the eeprom_write_block and read from the eeprom using eeprom_read_block from the avr/eeprom.h library

I've found this discussion that references EEMEM as an array in EEPROM.
Read/Write to EEPROM using AVR/EEPROM.h (SOLVED) - Programming Questions - Arduino Forum, as such, I have created arrays for the text messages and equivalent arrays in EEPROM using the EEMEM attribute (which I also really don't understand). The arrays in EEPROM have no specific location to them as far as I can see when using the EEMEM array. I'm assuming the compiler decides where to start each array.

If I write to eeprom using the eeprom_write_block per the attached code (it's incomplete because I don't know how to complete this code), what is the best method of locating the beginning of the string in EEPROM AFTER it's written?

#include <avr/eeprom.h>

#define NUM_MAX 17 // LCD String length (incl \0)
#define eeprom_busy_wait;

/****** LCD EEPROM Arrays *******/
char EEMEM lcdMsgLoc1[NUM_MAX];
char EEMEM lcdMsgLoc2[NUM_MAX];
char EEMEM lcdMsgLoc3[NUM_MAX];
char EEMEM lcdMsgLoc4[NUM_MAX];

/**** Known EEPROM Locations ****/
int msgPtr1 = 920;  // Known EEPROM location for lcdMsgLoc1 address
int msgPtr2 = 922;  // Known EEPROM location for lcdMsgLoc2 address
int msgPtr3 = 924;  // Known EEPROM location for lcdMsgLoc3 address
int msgPtr4 = 926;  // Known EEPROM location for lcdMsgLoc4 address

/********** STRINGS *************/
char lcdMsg1[NUM_MAX] = "Message Number 1";
char lcdMsg2[NUM_MAX] = "Message Number 2";
char lcdMsg3[NUM_MAX] = "Message Number 3";
char lcdMsg4[NUM_MAX] = "Message Number 4";

void setup(){

// LCD Text messages
    eeprom_write_block (lcdMsg1, lcdMsgLoc1, NUM_MAX);

    char *locAdd; // define a pointer
    locAdd = &lcdMsgLoc1[0]; // pointer points to address of lcdMsgLoc1[0]

    // write the address into another EEPROM location - ????
    // when ready to read string, read block starting at address written in EEPROM - ???
}

void loop()
{}

FWIW, my guess is to define a pointer to the address of the 0 element of the EEMEM array and write that address into a known location in EEPROM - but I have tried for a few days to figure this out to no avail. I'm not looking for someone to code this for me but rather tell me if I'm on the right track or not. I can go back to reading the C Programming Book by Kernighan and Ritchie if needed but this book is proving to be of little help for this.

Thanks in advance

This is not a direct answer to your question about EEPROM block access, which is a interesting topic. However, if your sole reason for considering storing messages in EEPROM is because of the amount of precious RAM these are consuming, you may aware that there is another alternative. That is forcing these to be stored in the flash memory instead of RAM using the F() macro: F() macro and PROGMEM - Programming Questions - Arduino Forum

Hi 6v6gt,

I did see that mentioned in a few posts and it seems like it might be an alternate approach. Are there pro's and cons for storing messages in flash vs EEPROM? My goal for sure is the minimization of SRAM usage. Are the messages better off in flash and if so, why?

Thanks for replying

Writing in flash is easy to do with F() and, say with a ATMEG328P (like in the Arduino Uno) you get 32KB which you share with the program memory. Unless your sketch is huge, you'll have a lot of spare flash memory.
With RAM you have only 2 KB and with EEPROM only 1KB.
Messages are quite static. The EEPROM is more usually used for information which is collected during the running of a program and which must survive a restart.
Also, if you are using the EEPROM to save RAM, you would probably need a separate sketch to load the EEPROM with your messages, otherwise you won't benefit much from the saving of RAM.

It is a separate sketch that loads EEPROM. I prepare the EEPROM first and then load the main sequencer sketch so there is large savings.

I included the avr/pgmspace.h library for the F() macro and am now looking at how to use if for my serial.writes to the serially enabled LCD from SparkFun. using the F() as part of the Serial.write does not work - it generates an error message and will not compile so I need to look at this much closer.

Many of these error messages are so cryptic that it can take hours just to figure out what it's telling me - ah, the trials of a newbie!!

OK, I decided to go with the PROGMEM approach and store in flash. This is working well and so I'll close this thread.

Thanks for the pointer on using Flash.