Hello,
I am trying to store and retrieve values from four 32000 char arrays stored in flash of an Arduino Mega 2560. Unfortunately, when I go to retrieve some values, the values printed out in the serial monitor are wrong.
I have looked at the PROGMEM section in the Arduino reference and at https://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html and am not able to figure out what is going wrong.
Currently, I am trying to use pgm_read_byte_near(), pgm_read_byte(), and pgm_read_byte_far() and all of them are giving the wrong values.
Interestingly, I get the right value when I store and retrieve values form only 1 array, so I'm guessing it has something to do with where and how the arrays are being stored.
Any help would be appreciated.
Code is too big to post here due to the arrays, so here is a link so others can replicate the issue:https://gofile.io/d/DgHjIF
Otherwise, here is the main snippet minus the arrays
#include <avr/pgmspace.h>
const char image1[32000] PROGMEM ={0x61, ...<large array>..., 0x31};
const char image2[32000] PROGMEM ={0x16, ...<large array>..., 0x31};
const char image3[32000] PROGMEM ={0x32, ...<large array>..., 0x31};
const char image4[32000] PROGMEM ={0x33, ...<large array>..., 0x31};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("I am working");
delay(1000);
for (int i = 0; i < 32000; i++) {
Serial.print(pgm_read_byte_near(image1+i), HEX);
Serial.print(" ");
Serial.print(pgm_read_byte(image1+i), HEX);
Serial.print(" ");
Serial.print(pgm_read_byte_far(image1+i), HEX);
Serial.print("\n");
delay(1000);
}
for (int i = 0; i < 32000; i++) {
Serial.print(pgm_read_byte_near(image2+i), HEX);
Serial.print(" ");
Serial.print(pgm_read_byte(image2+i), HEX);
Serial.print(" ");
Serial.print(pgm_read_byte_far(image2+i), HEX);
Serial.print("\n");
delay(1000);
}
for (int i = 0; i < 32000; i++) {
Serial.print(pgm_read_byte_near(image3+i), HEX);
Serial.print(" ");
Serial.print(pgm_read_byte(image3+i), HEX);
Serial.print(" ");
Serial.print(pgm_read_byte_far(image3+i), HEX);
Serial.print("\n");
delay(1000);
}
for (int i = 0; i < 32000; i++) {
Serial.print(pgm_read_byte_near(image4+i), HEX);
Serial.print(" ");
Serial.print(pgm_read_byte(image4+i), HEX);
Serial.print(" ");
Serial.print(pgm_read_byte_far(image4+i), HEX);
Serial.print("\n");
delay(1000);
}
}
void loop() {
// put your main code here, to run repeatedly:
}