Problem using avr/pgmspace

Hi there

I'm trying to put some constant data into flash RAM on my arduino uno/nano and using indirect referencing like Dean Camera in his tutorial (see link).

I understand the example in

and build a working sketch for it (see attached file)

Now I'd like to change the datatype from char to byte. And now I can't access the data via the 2nd array called wtime.

Any help on this?

Thx

FlashRAM_Pointer_Example.ino (2.01 KB)

Now I'd like to change the datatype from char to byte.

No problem. They are exactly the same size.

And now I can't access the data via the 2nd array called wtime.

Why not?

chess-levin:
Now I'd like to change the datatype from char to byte. And now I can't access the data via the 2nd array called wtime.

Any help on this?

I didn't look at your code, but most likely a simple type casting in the right place might help.

BTW: Why don't you post just a small code 'inline' in your message text, included in code tags? If you want people to download and install your code before they can have a quick look, perhaps not so many persons are interested in doing so, other as if you posted some lines of code 'inline' in your posting.

Here is the code

const char MenuItem1[] PROGMEM = "Menu Item 1\0";
const char MenuItem2[] PROGMEM = "Menu Item 2\0";
const char MenuItem3[] PROGMEM = "Menu Item 3\0";
const char * const MenuItemPointers [] PROGMEM = { MenuItem1 , MenuItem2 , MenuItem3 };

#define TERM 255
const byte wto[]  PROGMEM = {13,14,15,TERM};
const byte wpast[]  PROGMEM = {9,10,11,12,TERM};
const byte whalf[]  PROGMEM = {16,17,18,19,TERM};

const byte* wtime[] = {wto, wpast, whalf};


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("setup()");

  // using char the concept is working, see [REF2]
  char buffer[15];
  strcpy_P(buffer, (char *) pgm_read_word (&MenuItemPointers [0]));
  Serial.println(buffer);
  strcpy_P(buffer, (char *) pgm_read_word (&MenuItemPointers [1]));
  Serial.println(buffer);
  strcpy_P(buffer, (char *) pgm_read_word (&MenuItemPointers [2]));
  Serial.println(buffer);

  
  // using byte as datatype the concept is not working
  // lines marked with A should show the same result
  // same for B
  
  showWord(&wto[0]); // A
  showWord(&wpast[0]); // B
  
  showWord( (byte*) pgm_read_word (&wtime[0])); // A
  showWord( (byte*) pgm_read_word (&wtime[1]));  // B
  // using byte as datatype the concept is not working
  // lines marked with A should show the same result
  // same for B

So, the problem would appear to be in the mysterious function showWord().

Why a function called showWord() is expected to deal with byte arrays is a mystery.