Go Down

Topic: [Resolved] PROGMEM in Arduino IDE 1.6.0 (Read 12392 times) previous topic - next topic

liuzengqiang

Feb 12, 2015, 08:42 am Last Edit: Feb 16, 2015, 06:15 pm by liudr
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:

Code: [Select]
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:
Code: [Select]

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:
Code: [Select]

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
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

pYro_65

#1
Feb 12, 2015, 02:43 pm Last Edit: Feb 12, 2015, 02:48 pm by pYro_65
The array must be constant, you've created an array of constant elements.

Code: [Select]
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.
Forum Mod anyone?
https://arduino.land/Moduino/

liuzengqiang

Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

liuzengqiang

I tested and Pyro's solution works for both 1.6.0 and 1.0.6
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

my_legend_mm

#4
Mar 14, 2015, 04:29 pm Last Edit: Mar 14, 2015, 04:30 pm by my_legend_mm Reason: reomve personal info :)
Hi every one .
I'm working with TFTLCD .
How solve this error .

Code: [Select]
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  :)

pYro_65

@my_legend_mm,

Quote
static const unsigned char font[] PROGMEM = {
Forum Mod anyone?
https://arduino.land/Moduino/

my_legend_mm

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 .

liuzengqiang

Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

my_legend_mm

#8
Mar 17, 2015, 07:56 pm Last Edit: Mar 17, 2015, 07:58 pm by my_legend_mm
 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 :)

liuzengqiang

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.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

ninja2

#10
Oct 28, 2015, 10:21 pm Last Edit: Oct 28, 2015, 10:34 pm by ninja2
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:

Code: [Select]

/* -- 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:

Code: [Select]
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

ninja2

cancel !

fixed it by replacing prog_char with const char

thanks

Go Up