Hi all,
I've got a sketch I wrote that has LOTS of static text in it (menu items and sprintf() format strings).
Suspecting that PROGMEM is not working for me, I tried an experiment: I made a little function just filled with a lot of text:
// yes of course #include <avr/pgmspace.h> is loaded....
void zzz(void)
{
prog_uchar test_message[] PROGMEM = {
"A is for apple, J is for jacks. Cinnamon Toasty Apple Jacks. Dig-Um!\r\n"
// LOTS more of the same line.......
"A is for apple, J is for jacks. Cinnamon Toasty Apple Jacks. Dig-Um!\r\n"
};
}
This layout is directly from the Arduino "PROGMEM" reference: PROGMEM - Arduino Reference
If I compile this code, the IDE says it's 19,000 bytes out of 258,048 (a MEGA2560 R3 board).
These formats also result in exactly the same code (and 19,000 byte size):
const char *test_message = "A is for apple.....";
const char test_message[] = { "A is for apple....." };
If, however, I use the "FLASH_STRING" syntax from the "Flash" library - Flash | Arduiniana
void zzz(void)
{
FLASH_STRING(test_message,
"A is for apple, J is for jacks. Cinnamon Toasty Apple Jacks. Dig-Um!\r\n"
// LOTS more of the same line.......
"A is for apple, J is for jacks. Cinnamon Toasty Apple Jacks. Dig-Um!\r\n"
);
}
...the code is now 46,094 out of 258,048, which tells me that FLASH_STRING is working but PROGMEM is not.
So, the question is, HOW to make PROGMEM work? I would appreciate a code sample, not a link since of course the info at the link DOESN'T WORK!
Also, if this means anything, when I use PROGMEM (or if I don't), the code complies to 19,000 bytes and the string gets put at the BOTTOM of the block of binary (I examined the .HEX file). However, if I use FLASH_STRING, the string is placed near the TOP of the binary block.
I've GOT to make this work because I have LOTS of strings and it simply won't fit unless it's in flash.
Any help will be appreciated. Thanks!
-- Roger