How to load variables from SD Card at startup

Hi all,

I have a working code that reads some look up tables for RGB LED's (and no, I havent posted it, before someone comments on that). With all working I can customize the color pattern by changing the look up table(s), but I need to program the device again.

My aim would be to read the look up table(s) from an SD Card, but performing a "copy at startup" in which the data would be copied to the local RAM and accessed as usual during normal code execution. At this point the card could be removed. This would avoid the need to reprogram the device each time a new configuration was required.

I am struggling to find an example doing something similar to this and would be gratefull for some hints.

Regards

Hi

Within my Arduino application that runs at http://www.2wg.co.nz/ I do periodic backups and the system restores its memory arrays from the latest backup whenever it is restarted.

The source code is all there for you to download and review. For the reload function look for the LoadRecentMemoryBackupFile() procedure.

With 837 posts to this forum you should be able to work it all out.

Cheers

Catweazle NZ

I use the SdFat Library. It comes with examples that you can look. I used the FileInfo example as a pattern for my own project.

Besides initilalizing the SD card, you will need some code like this

struct Lut
{
	// the Data you want to save 
};

Lut lut; 

void readLut()
{
	SdFile f;
	f.open("path-name", O_RDONLY);
	f.read(&lut, sizeof(Lut));
	f.close();
}

void writeLut()
{
	SdFile f;
	f.open("path-name", O_WRITE);
	f.write(&lut, sizeof(Lut));
	f.close();
}