[Resolved] PROGMEM in Arduino IDE 1.6.0

I’ve been using PROGMEM prog_char text=“hello”; for ages without problems.
With the new IDE, it complains about the prog_char. I guess it is because of the DEPRECATED status of the typedef. So I changed to const char PROGMEM text=“hello” OK, it works on 1.0.x and 1.6.0

But then I also have SRAM arrays that store pointers (FLASH address) to various PROGMEM strings. I used to do:

PROGMEM const char *phi_prompt_lcd_ch_item[] = {phi_prompt_lcd_ch0, phi_prompt_lcd_ch1, phi_prompt_lcd_ch2, phi_prompt_lcd_ch3, phi_prompt_lcd_ch4, phi_prompt_lcd_ch5}; ///< Custom LCD character char array addresses.

This way I can save some SRAM. Now this definition is also complained upon in 1.6.0. I don’t really know how to fix it. I tried to remove PROGMEM but my program didn’t run (probably grabbed wrong stuff in FLASH).

Error:

error: variable 'phi_prompt_lcd_ch_item' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 PROGMEM const char * phi_prompt_lcd_ch_item[] = {phi_prompt_lcd_ch0, phi_prompt_lcd_ch1, phi_prompt_lcd_ch2, phi_prompt_lcd_ch3, phi_prompt_lcd_ch4, phi_prompt_lcd_ch5}; ///< Custom LCD character char array addresses.

So PROGMEM alone with the const char * indicates that the pointers reside in FLASH in past versions (possibly avr gcc version instead of Arduino IDE version). Now I tried a few orders and even two PROGMEM but couldn’t get this line to compile. Any suggestions? Thanks.

My final version was identical to this AVR GCC 2013 tutorial I found:

const char phi_prompt_lcd_ch0[] PROGMEM ={ 4,14,31,64,31,31,31,31,0}; ///< Custom LCD character: Up triangle with block
const char phi_prompt_lcd_ch1[] PROGMEM ={ 4,14,31,64,64,64,64,64,0}; ///< Custom LCD character: Up triangle 
const char phi_prompt_lcd_ch2[] PROGMEM ={31,31,31,31,64,64,64,64,0}; ///< Custom LCD character: Top block
const char phi_prompt_lcd_ch3[] PROGMEM ={64,64,64,64,31,31,31,31,0}; ///< Custom LCD character: Bottom block
const char phi_prompt_lcd_ch4[] PROGMEM ={64,64,64,64,64,31,14, 4,0}; ///< Custom LCD character: Down triangle
const char phi_prompt_lcd_ch5[] PROGMEM ={31,31,31,31,64,31,14, 4,0}; ///< Custom LCD character: Down triangle with block
const char * phi_prompt_lcd_ch_item[] PROGMEM = {phi_prompt_lcd_ch0, phi_prompt_lcd_ch1, phi_prompt_lcd_ch2, phi_prompt_lcd_ch3, phi_prompt_lcd_ch4, phi_prompt_lcd_ch5}; ///< Custom LCD character char array addresses.

http://deans-avr-tutorials.googlecode.com/svn/trunk/Progmem/Output/Progmem.pdf

The array must be constant, you've created an array of constant elements.

const char * const phi_prompt_lcd_ch_item[] PROGMEM = {
  /* Custom LCD character char array addresses. */
  phi_prompt_lcd_ch0, 
  phi_prompt_lcd_ch1, 
  phi_prompt_lcd_ch2, 
  phi_prompt_lcd_ch3, 
  phi_prompt_lcd_ch4, 
  phi_prompt_lcd_ch5
};

From right to left:

An array which is constant containing char pointers which are constant.

Pyro,

Thank you!

I tested and Pyro’s solution works for both 1.6.0 and 1.0.6

Hi every one . I'm working with TFTLCD . How solve this error .

C:\Users\\Documents\Arduino\libraries\TFTLCD\glcdfont.c:9:23: error: variable 'font' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 static unsigned char  font[] PROGMEM = {
                       ^

thanks :)

@my_legend_mm,

static const unsigned char font PROGMEM = {

Thanks @pYro_65

it's work fine :) .

But i have another problem cam you help me :D i'm add some library , this Lib not work how remove it and his example .

thanks again .

Which library? What error message?

TFT Library , i have this LCD in this comment

but i can't make it work , i'm try many library but it's still white . can you help me , thanks for your reply :)

You need to provide a direct link to the product and the library. Nobody is going to dig that out of a 5-page discussion thread for you. Sorry.

I also have been using PROGMEM for ages but in process of upgrading IDE from 1.0.6 to 1.6.4 I get these errors like below for code that previously compiled OK:

SCOO3:256: error: ‘prog_char’ does not name a type
.
.
SCOO3:267: error: variable ‘menu_table’ must be const in order to be put into read-only section by means of ‘attribute((progmem))’
SCOO3:267: error: ‘menu_0’ was not declared in this scope
.
.
‘prog_char’ does not name a type

Here’s the relevant code section. I’m not good at pointers etc so any suggestions to correct this code much appreciated:

/* -- MENU ---------------------------------------------------------------------- */
prog_char menu_0[]   PROGMEM = "COMMAND MENU:";
prog_char menu_1[]   PROGMEM = "      D: Directory of SD card";
prog_char menu_2[]   PROGMEM = "      R: Reset RTC time";
prog_char menu_3[]   PROGMEM = "      S: Set RTC time";
prog_char menu_4[]   PROGMEM = "      +: drift factor +1 (for a slow clock)";
prog_char menu_5[]   PROGMEM = "      -: drift factor -1 (for a fast clock)";
prog_char menu_6[]   PROGMEM = "      F: <not used>";
prog_char menu_7[]   PROGMEM = "      W: Write drift_factor into [RTC] NVRAM";
prog_char menu_8[]   PROGMEM = "      Z: Zero the drift_factor [RTC]";
prog_char menu_9[]   PROGMEM = "      N: Report values in [RTC] NVRAM";
prog_char menu_10[]  PROGMEM = "0,1...6: Set mode to 0,1,2,3,4,5 or 6";
PROGMEM const char *menu_table[]={menu_0,menu_1,menu_2,menu_3,menu_4,
                                  menu_5,menu_6,menu_7,menu_8,menu_9,menu_10};

Based on comments in this thread I changed as shown below. It removed one error: variable ‘menu_table’ must be const, but not the others:

const char * const menu_table[] PROGMEM = {menu_0,menu_1,menu_2,menu_3,menu_4,
                                           menu_5,menu_6,menu_7,menu_8,menu_9,menu_10};

But I’d also welcome suggestions to get away from PROGMEM altogether as it doesn’t seem very elegant, so hoping there’s a simpler way to do this

cancel !

fixed it by replacing prog_char with const char

thanks