I am leading with a strange error using the PROGMEM space that I can't understand. Here is the temp code that I have been using to figure out the problem:
char stop0to[] PROGMEM= "Terminal Inicio" ;
char stop1to[] PROGMEM= "Juan B Justo" ;
char stop2to[] PROGMEM= "Oro" ;
char stop3to[] PROGMEM= "Charcas" ;
char* StopsNameTo[] PROGMEM={
stop0to,stop1to,stop2to,stop3to};
char stop0from[] PROGMEM= "Terminal Inicio" ;
char stop1from[] PROGMEM= "Ayacucho" ;
char stop2from[] PROGMEM= "Uriburu" ;
char stop3from[] PROGMEM= "Pueyrredon" ;
char* StopsNameFrom[] PROGMEM={
stop0from,stop1from,stop2from,stop3from};
char** StopsName[] PROGMEM= {
StopsNameTo, StopsNameFrom};
char stop_name_aux[30];
void setup(){
Serial.begin(9600);
Serial.println(GetStopName(1,0));
}
void loop(){
}
char* GetStopName(int Stop_Id, char route)
{
strcpy_P(stop_name_aux, (PGM_P)pgm_read_word(&(StopsName[route][Stop_Id])));
return stop_name_aux;
}
route could be 0,1 and Stop_Id could be 0,1,2,3.
So basically, I want to retrieve the strings that are in the Flash memory, but the code above is not working. It prints random characters. The weiredest part is that if I hardcode the "route" var with 0 or 1 like this in the GetStopName function:
char* GetStopName(int Stop_Id, char route)
{
strcpy_P(stop_name_aux, (PGM_P)pgm_read_word(&(StopsName[0][Stop_Id])));
return stop_name_aux;
}
then it works, but it won't work if I pass the 0 value to the function through the route parameter like in the original code.
Also I've found out that if the code is like this:
char* GetStopName(int Stop_Id, char route)
{
if(!route)
strcpy_P(stop_name_aux, (PGM_P)pgm_read_word(&(StopsName[route][Stop_Id])));
return stop_name_aux;
}
then it also works!
I think it's a PGMSPACE pointer and var issue. But I can't work it out.
Thanks!
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.