Augusto Picciani
Augusto Picciani

Reputation: 804

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

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"};

Upvotes: 7

Views: 8069

Answers (2)

Daniel Gehriger
Daniel Gehriger

Reputation: 7468

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")))

Upvotes: 3

Arkku
Arkku

Reputation: 42159

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

Upvotes: 7

Related Questions