Using PROGMEM int array

I'm new to coding with Arduinos. I'm using a Mega 2560.
I want to store an array of ints in the flash memory and then read it out, eventually write it to an SD card.
I'm having issues actually reading the array from flash.

Here's what I have:

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;
const int int_array[] PROGMEM = {0,1,2,3,4};
char buffer[30]; // Needs to be big enough for largest string held

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

// Hardware SS pin (Mega 53) must be output or SD library functions won't work
pinMode(SS, OUTPUT);

// Make sure you've got the write chip select
if (!SD.begin(chipSelect))
{
Serial.print("SD initialization failed!");
return;
}
Serial.print("SD initialization complete.\n");

for (int i = 0; i < 6; i++)
{
strcpy_P(buffer, pgm_read_word(&int_array*)); // Necessary casts and dereferencing, just copy.*

  • Serial.print(buffer);*
  • Serial.print("\n");*
  • delay( 500 );*
  • }*
  • Serial.print("Done.");*
    }
    void loop() {}
    The output that I get is:
    SD initialization complete.
  • ⸮*

    ;⸮
    ⸮⸮1P ⸮
    Done.
    I've been trying to figure this out for a couple of days, and I'm at a loss. Any help you guys could give me would be much appreciated.

You've placed an array of integers in PROGMEM. Why are you trying to read it as a character string?

I've tried pgm_read_byte as well and I still get nonsense as an output. None of the pgm_read_XXX give me the output I want.

I see no value added in trying to convert an integer into a char string and store it in a buffer. Just work with the integers:

const uint16_t int_array[] PROGMEM = {0, 1, 2, 3, 4};
const uint8_t numElements = sizeof(int_array) / sizeof(int_array[0]);

void setup() {
  uint16_t readValue;
  Serial.begin(115200);
  delay(2000);

  for (uint8_t i = 0; i < numElements; i++)
  {
    readValue = pgm_read_word(&int_array[i]);
    Serial.println(readValue);
  }
  Serial.println("Done");
}

void loop() {}