[SOLVED] Unable to read data from PROGMEM

I'm got a sketch for a Arduino Uno where I need to store 8k of data. I have to use progmem otherwise the Uno will not have enough memory.

Guess I don't understand PROGMEM as the below sketch is not printing the correct data:

const uint32_t bin_file[] PROGMEM = { 0x09, 0x80, 0xf6, 0x8e, 0xc3, 0xc2, 0xcd, 0x38, 0x30, 0xa2, 0xc8, 0x8e, 0x16, 0xd0, 0x20, 0xa3 };


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

}


void loop() {

  for (long x = 0; x < 15; x++) {

    Serial.print(bin_file[x], HEX);
  }

  while (1) {
  }



}

I would have expected the values in the array to be printed however I seem to be getting other values:

0100000B8B8B8B88700000301500202020220202B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8B8

If however I use:

Serial.print(bin_file[0], HEX);

it returns the first value correctly. (But not using x)

You need to read the reference pages about how to read PROGMEM correctly - you're currently reading the values from RAM

    Serial.print(pgm_read_dword(&bin_file[x]), HEX);

should work.

Program Space Utilities

Perfect. Thanks very much. Working as expected.

Something new learnt today.