[SOLVED] Problem with prog_read_word()

Hi,

I am a newbie... I have ATMega2560 with 16x2 LCD shield and am using Atmel Studio to build my code with Arduino 1.03. It is not in sketch format... Just a bunch of *.h and *.cpp files...
I am trying to do the following but I sometimes get unexpected characters or garbage being printed to my LCD...

const char menu_1[] PROGMEM = "General Motors";
const char menu_2[] PROGMEM = "Ford";
const char menu_3[] PROGMEM = "Chrysler";
const char menu_4[] PROGMEM = "Honda";
const char menu_5[] PROGMEM = "Toyota";
const char menu_6[] PROGMEM = "Nissan";

const char *menu_str[]  = { menu_1, menu_2, menu_3, menu_4, menu_5, menu_6 };

char lcd_buf[MAX_LCD_STR]
strcpy_P(lcd_buf, (char*) pgm_read_word(&(menu_str[0])));
lcd.print(lcd_buf);

But if I do the following, I get the correct result

strcpy_P(lcd_buf, menu_str[0]);

That makes me think there is something wrong with the way I am using pgm_read_word().
So I thought may be I should define menu_str [] in the following way

const char *menu_str[] PROGMEM = { menu_1, menu_2, menu_3, menu_4, menu_5, menu_6 };

But the above line does not compile. It says menu_str should be declared as const. Well, it is const... So I dont know what is wrong.

Thanks for your help...

Any ideas anyone?

Try:

#include <avr/pgmspace.h>  //Needed for placing data into Flash (Main) Memory
etc.


prog_char menu_1[] PROGMEM = "General Motors";
etc.

PROGMEM const char *menu_str[]  = { menu_1, menu_2, menu_3, menu_4, menu_5, menu_6 };

char lcd_buf[MAX_LCD_STR]
strcpy_P(lcd_buf, (char*) pgm_read_word(&(menu_str[0])));
lcd.print(lcd_buf);

There is something wrong with the documentation, however this compiles:

const char menu_1[] PROGMEM = "General Motors";
const char menu_2[] PROGMEM = "Ford";
const char menu_3[] PROGMEM = "Chrysler";
const char menu_4[] PROGMEM = "Honda";
const char menu_5[] PROGMEM = "Toyota";
const char menu_6[] PROGMEM = "Nissan";

const char * menu_str [] PROGMEM = { menu_1, menu_2, menu_3, menu_4, menu_5, menu_6 };

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();
  Serial.println ("Start.");
  char lcd_buf [100];
  for (int i = 0; i < 6; i++)
    {
    strcpy_P (lcd_buf, (char * ) pgm_read_word (&menu_str [i]));
    Serial.println (lcd_buf);
    }
  }  // end of setup

void loop () { }

Output:

Start.
General Motors
Ford
Chrysler
Honda
Toyota
Nissan

Thanks guys... None of the solutions worked, that's because I am compiling in Atmel Studio 6. The compiler in Atmel Studio does not like the way I declared menu_str[ ]. It wanted the following

 const char* const menu_str[] PROGMEM

instead of

 const char* menu_str[] PROGMEM

I figured out after some more search over here http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=120881&start=0

Just wanted to post this so that someone else facing the same issue would know what to do...

Thanks for your help!