Hi,
I am relatively new to Arduino, less than a year.
I am having problems learning how to use PROGMEM. I have an OLED screen and have been playing with the "lorem_ipsum" example but that is my limit with using PROGMEM.
I want to learn more so I found this, PROGMEM - Arduino Reference, example...
/*
PROGMEM string demo
How to store a table of strings in program memory (flash),
and retrieve them.
Information summarized from:
http://www.nongnu.org/avr-libc/user-manual/pgmspace.html
Setting up a table (array) of strings in program memory is slightly complicated, but
here is a good template to follow.
Setting up the strings is a two-step process. First define the strings.
*/
#include <avr/pgmspace.h>
prog_char string_0[] PROGMEM = "String 0"; // "String 0" etc are strings to store - change to suit.
prog_char string_1[] PROGMEM = "String 1";
prog_char string_2[] PROGMEM = "String 2";
prog_char string_3[] PROGMEM = "String 3";
prog_char string_4[] PROGMEM = "String 4";
prog_char string_5[] PROGMEM = "String 5";
// Then set up a table to refer to your strings.
PROGMEM const char *string_table[] = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5 };
char buffer[30]; // make sure this is large enough for the largest string it must hold
void setup()
{
Serial.begin(9600);
}
void loop()
{
/* Using the string table in program memory requires the use of special functions to retrieve the data.
The strcpy_P function copies a string from program space to a string in RAM ("buffer").
Make sure your receiving string in RAM is large enough to hold whatever
you are retrieving from program space. */
for (int i = 0; i < 6; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
Serial.println( buffer );
delay( 500 );
}
}
...but when I try to run the array example I get these errors...
ProgmemTest.ino:12:18: error: variable ‘string_0’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
ProgmemTest.ino:13:18: error: variable ‘string_1’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
ProgmemTest.ino:14:18: error: variable ‘string_2’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
ProgmemTest.ino:15:18: error: variable ‘string_3’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
ProgmemTest.ino:16:18: error: variable ‘string_4’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
ProgmemTest.ino:17:18: error: variable ‘string_5’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
ProgmemTest.ino:19:28: error: variable ‘string_table’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
I have changed the lines like this...
prog_char string_1[] PROGMEM = "String 1";
...to ones like this...
prog_char const string_1[] PROGMEM = "String 1";
...and I can eliminate most of the errors but I don't know how to change this line...
PROGMEM const char *string_table[] =
I have tried many hours to google a solution and all I can find is:
- It could be something to do with the version of the IDE I have (1:1.0.5+dfsg2-1)
- it could be something to do with "prog_char" (dunno how this affects the string_table line)
- it could be something to do with the gcc compiler on my PC (?)
Ultimately I am lost and I need a working example to tinker with so that I can learn how to use it.
Can anyone help me?
Cheers,
Glen
Arduino IDE running on Linux Mint
Testing with a LeoStick but I also have an Eleven if it could possibly be board related