Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C - how to use PROGMEM to store and read char array

Tags:

c

arduino

I have three char arrays, and I don't want Arduino store those in SRAM, so I want to use PROGMEM to store and read in flash, instead.

char *firstArr[]={"option 1","option 2","option 3","option 4"};
char *secondArr[]={"test 1","test 2"};
like image 932
Augusto Picciani Avatar asked Oct 26 '12 20:10

Augusto Picciani


2 Answers

There's an example on how to do precisely this on the Arduino website. (See under "Arrays of strings".)

like image 125
Arkku Avatar answered Oct 30 '22 01:10

Arkku


Yes, there is an example on the Arduino web site. But I want to make you aware of a compiler bug in GCC, and the following work-around:

/**
 * Alternative to PROGMEM storage class
 * 
 * Same effect as PROGMEM storage class, but avoiding erroneous warning by
 * GCC.
 * 
 * \see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34734
 */
#define PROGMEM_ __attribute__((section(".progmem.data")))
like image 34
Daniel Gehriger Avatar answered Oct 29 '22 23:10

Daniel Gehriger