user54242: I am unable to access elements of a 2D PROGMEM array from inside a loop. Please see the following example:
const byte a1[] PROGMEM = {'a', 'b', 'c', 'd'};
const byte a2[] PROGMEM = {'e', 'f', 'g', 'h', 'i'};
const byte a3[] PROGMEM = {'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'};
const byte a4[] PROGMEM = {'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

const byte * const arr[] PROGMEM = {a1, a2, a3, a4};

void setup() {
  Serial.begin(9600);

  Serial.println(pgm_read_byte(&(arr[0][0])));
  Serial.println(pgm_read_byte(&(arr[1][0])));
  Serial.println(pgm_read_byte(&(arr[2][0])));
  Serial.println(pgm_read_byte(&(arr[3][0])));
  for (int i = 0; i < 4; i++) {
    Serial.print(i);
    Serial.print(":");
    Serial.println(pgm_read_byte(&(arr[i][0])));
  }
  int j = 0;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 1;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 2;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 3;
  Serial.println(pgm_read_byte(&(arr[j][0])));
}

void loop() {

}

The output is:
97
101
106
114
0:12
1:174
2:12
3:148
97
101
106
114

I verified and re-verified the syntax so many times. could not find anyone facing similar issue. I am at my wits end why it would not print correct values inside the loop. Any ideas?
EDIT: expected output is:
97
101
106
114
0:97
1:101
2:106
3:114
97
101
106
114


user54242: After going through link given by Juraj above again, I could make it work as follows:
const byte a1[] PROGMEM = {'a', 'b', 'c', 'd'};
const byte a2[] PROGMEM = {'e', 'f', 'g', 'h', 'i'};
const byte a3[] PROGMEM = {'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'};
const byte a4[] PROGMEM = {'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

const byte * const arr[] PROGMEM = {a1, a2, a3, a4};

void setup() {
  Serial.begin(74880);

  Serial.println(pgm_read_byte(&(arr[0][0])));
  Serial.println(pgm_read_byte(&(arr[1][0])));
  Serial.println(pgm_read_byte(&(arr[2][0])));
  Serial.println(pgm_read_byte(&(arr[3][0])));
  for (int i = 0; i < 4; i++) {
    Serial.print(i);
    Serial.print(":");
    Serial.println(pgm_read_byte_near(pgm_read_word(&(arr[i])) + 0));
  }
  int j = 0;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 1;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 2;
  Serial.println(pgm_read_byte(&(arr[j][0])));
  j = 3;
  Serial.println(pgm_read_byte(&(arr[j][0])));
}

void loop() {

}

Now it shows the expected output and access from inside loop using variable index is possible. Thanks.

54242: <p>I am unable to access elements of a 2D PROGMEM array from inside a loop. Please see the following example:</p>

<pre><code>const byte a1[] PROGMEM = {'a', 'b', 'c', 'd'};
const byte a2[] PROGMEM = {'e', 'f', 'g', 'h', 'i'};
const byte a3[] PROGMEM = {'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'};
const byte a4[] PROGMEM = {'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

const byte * const arr[] PROGMEM = {a1, a2, a3, a4};

void setup() {
  Serial.begin(9600);

  Serial.println(pgm_read_byte(&amp;(arr[0][0])));
  Serial.println(pgm_read_byte(&amp;(arr[1][0])));
  Serial.println(pgm_read_byte(&amp;(arr[2][0])));
  Serial.println(pgm_read_byte(&amp;(arr[3][0])));
  for (int i = 0; i &lt; 4; i++) {
    Serial.print(i);
    Serial.print(":");
    Serial.println(pgm_read_byte(&amp;(arr[i][0])));
  }
  int j = 0;
  Serial.println(pgm_read_byte(&amp;(arr[j][0])));
  j = 1;
  Serial.println(pgm_read_byte(&amp;(arr[j][0])));
  j = 2;
  Serial.println(pgm_read_byte(&amp;(arr[j][0])));
  j = 3;
  Serial.println(pgm_read_byte(&amp;(arr[j][0])));
}

void loop() {

}
</code></pre>

<p>The output is:</p>

<pre><code>97
101
106
114
0:12
1:174
2:12
3:148
97
101
106
114
</code></pre>

<p>I verified and re-verified the syntax so many times. could not find anyone facing similar issue. I am at my wits end why it would not print correct values inside the loop. Any ideas?</p>

<p>EDIT: expected output is:</p>

<pre><code>97
101
106
114
0:97
1:101
2:106
3:114
97
101
106
114
</code></pre>
 54242: <p>After going through link given by Juraj above again, I could make it work as follows:</p>

<pre><code>const byte a1[] PROGMEM = {'a', 'b', 'c', 'd'};
const byte a2[] PROGMEM = {'e', 'f', 'g', 'h', 'i'};
const byte a3[] PROGMEM = {'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q'};
const byte a4[] PROGMEM = {'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

const byte * const arr[] PROGMEM = {a1, a2, a3, a4};

void setup() {
  Serial.begin(74880);

  Serial.println(pgm_read_byte(&amp;(arr[0][0])));
  Serial.println(pgm_read_byte(&amp;(arr[1][0])));
  Serial.println(pgm_read_byte(&amp;(arr[2][0])));
  Serial.println(pgm_read_byte(&amp;(arr[3][0])));
  for (int i = 0; i &lt; 4; i++) {
    Serial.print(i);
    Serial.print(":");
    Serial.println(pgm_read_byte_near(pgm_read_word(&amp;(arr[i])) + 0));
  }
  int j = 0;
  Serial.println(pgm_read_byte(&amp;(arr[j][0])));
  j = 1;
  Serial.println(pgm_read_byte(&amp;(arr[j][0])));
  j = 2;
  Serial.println(pgm_read_byte(&amp;(arr[j][0])));
  j = 3;
  Serial.println(pgm_read_byte(&amp;(arr[j][0])));
}

void loop() {

}
</code></pre>

<p>Now it shows the expected output and access from inside loop using variable index is possible. Thanks.</p>
