Pointer to PROGMEM bidimensional char array
hi all,
first of thank answers i've found here browsing forum : )
to go straight point: i'm having little issue getting address of progmem 2d array.
this code works fine:
it prints expected output: "str00".
while 1 prints garbage:
i've read excellent gammon progmem guide too, , adjusted code it:
but still no luck.
feeling there's obvious i'm missing...
i know access directly data with:
but maybe more convenient able pointer various elements of 3d data structure, still have implement rest (basically, i'm progmem'ed dale gass big fonts 16x2 lcd, adapting scrolling make them work on 20x4 lcd and, hopefully, on other lcd sizes).
and, way, i'd understand how correctly pointer in situation : )
hope can help.
first of thank answers i've found here browsing forum : )
to go straight point: i'm having little issue getting address of progmem 2d array.
this code works fine:
code: [select]
const char temp[][2][6] = {
/*0 */ {"str00", "str01"},
/*1 */ {"str10", "str11"},
/*2 */ {"str20", "str21"},
};
void setup() {
serial.begin(115200);
while (!serial) {}
serial.println("ready:");
char (*ptr)[6] = &temp[0][0];
serial.println(ptr[0]);
serial.println("exit");
serial.end();
}
void loop() {
}
it prints expected output: "str00".
while 1 prints garbage:
code: [select]
const char temp[][2][6] progmem = {
/*0 */ {"str00", "str01"},
/*1 */ {"str10", "str11"},
/*2 */ {"str20", "str21"},
};
void setup() {
serial.begin(115200);
while (!serial) {}
serial.println("ready:");
char (*ptr)[6] = pgm_read_word(&temp[0][0]);
serial.println(ptr[0]);
serial.println("exit");
serial.end();
}
void loop() {
}
i've read excellent gammon progmem guide too, , adjusted code it:
code: [select]
const char temp[][2][6] progmem = {
/*0 */ {"str00", "str01"},
/*1 */ {"str10", "str11"},
/*2 */ {"str20", "str21"},
};
void setup() {
serial.begin(115200);
while (!serial) {}
serial.println("ready:");
char * ptr = (char *) pgm_read_word (&temp[0][0]);
char buffer [6];
strcpy_p (buffer, ptr);
serial.println (buffer);
serial.println("exit");
serial.end();
}
void loop() {
}
but still no luck.
feeling there's obvious i'm missing...
i know access directly data with:
code: [select]
char c = pgm_read_byte(&temp[0][0][0]);
serial.println(c);
but maybe more convenient able pointer various elements of 3d data structure, still have implement rest (basically, i'm progmem'ed dale gass big fonts 16x2 lcd, adapting scrolling make them work on 20x4 lcd and, hopefully, on other lcd sizes).
and, way, i'd understand how correctly pointer in situation : )
hope can help.
there no pointers in multidimensional char array.
just read bytes offsets pgm_read_byte().
just read bytes offsets pgm_read_byte().
Arduino Forum > Using Arduino > Programming Questions > Pointer to PROGMEM bidimensional char array
arduino
Comments
Post a Comment