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.