So... I want to use a 256 byte lookup table in a project. I have a number of options on how and where to store it and I'm trying to figure which is the best approach.
The lookup table will be read-only while the controller is using it. However it will need to be occasionally updated. My project includes an SD card for logging, so I can put a file on there with the data, and update the file on the card when necessary.
I considered doing lookups directly against the file, but I don't see any way with the SD library to do random-access byte-by-byte reads of a file. If I wanted, say, byte #203, is there a way to quickly get just that byte without reading thru the whole file up to that point? There will be lots of lookups and speed is an issue.
I considered reading it from that file and putting it in an array in regular ram. This is the simplest approach (KISS). I'm doing this project on a Mega and although I'm using a good bit of the ram already, I still have plenty left. It's simple enough, and would certainly be fast. Just seems to me like poor programming. It goes against many of the rules I've been taught about efficient use of resources on microcontrollers. It's conceivable that I may need that ram for other things later.
Likewise, I considered reading it from the file and putting it into EEPROM. I can read it from EEPROM with a base address + an offset. To reduce boot time and wear on the EEPROM, I would read the file from the card only if it exists and put it into EEPROM then delete or rename the file. I know EEPROM is slow to write, but I think it reads pretty quickly doesn't it?
Then finally, I've thought about how I might put it into flash. My research seems to indicate that writing to flash at runtime is complex, and requires functions in the bootloader. So reading a new file from the SD card and having the controller place it into flash does not seem practical???
Next I thought about how I might be able to have that data in a separate file on my computer, and somehow include it when I compile. The included file would have to be in a format easily created by Excel which is where the master copy of the data is stored and updated. I can create a csv, or even raw binary, but having Excel create a c++ file would involve some sophisticated macros.
I would love to hear how you all think I should approach this. Can someone give me an overview of how I might be able to do quick random access on the file on the SD card, or maybe how I could easily include this data with my compile? Or other techniques? I always love learning a new trick!