Defining a const array with a loop?

Status
Not open for further replies.
Hi everyone,

I've been searching all over the web for the past few days and I can't seem to figure out what the best way to approach this issue is - curious if anyone else on here has bumped into it before?

I'm working on an project that requires a fairly large 2D array of floats (1024 x 1024), that I need to read from an SD card into the Teensy's memory (the SD reading speed is just a tiny bit too slow for the project). I'm working with the Teensy 4.1, so this array is too large to store in RAM, but as far as I understand, could fit in flash memory. This works out well for me, as the array basically won't change after it's been written into flash, so I won't be wearing out the flash. From what I've read, it seems that defining the array as const floats is all I need to do store it in flash, however I'm unsure of the correct way to assign values to it, given that I need to read them one by one off the SD card with a loop and, with the memory being read only, I guess I need to initialize and define them at the same time?

I'm a bit unsure about what the best way to go about this is? Probably an inexperience thing haha. Would love to hear anyone else's thoughts on it :)

Thanks!
 
I guess I need to initialize and define them at the same time?

Yes.

The syntax should look something like this:


Code:
PROGMEM const float myArrayOfNumbers[] = {
  1.123, 2.345, 3.456, 5.555, // etc...
};


If you can't create all the numbers in advance and put them into your code, if they really must come from a file stored on the SD card, then perhaps adding the PSRAM chip would be a way to make this project work?

https://www.pjrc.com/store/psram.html
 
Status
Not open for further replies.
Back
Top