Announcement

Collapse
No announcement yet.

Saving Variables to the uSD Card

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Saving Variables to the uSD Card

    I know this an old thread. I am very new to 4Duino. I am trying to save just a couple variables to the SD card. The command Display.file_Write("HELLO WORLD",9,handle); works fine for a constant string. But I need to save a changing variable. The user will change a setting on the display and then dynamically be able to save the new setting value so when the device starts up it has the new setting instead of the default setting. I tried Display.file_PutC and Display.file_PutS but I must not fully understand what value to provide. I tried Strings, Char Arrays and I always get an error. Anyone have a simple example of how to save a changing variable for the 4Duino?

  • #2
    Here is my function that saves parameter data to the sd.. I hope this helps. It creates a text file that has a comma separated list of values that I load on boot. for ex 1,2,3,4,12,23,34,1234,2345,456,etc.

    Look up the file handling functions and examples in the Picaso-Serial-Arduino-Library. Also you can get some usage information from the picaso serial library manual.

    Code:
    void writeSettingsToDisk(char fileName[16])
    {
    Display.gfx_Cls();
    Display.txt_Width(1);
    Display.txt_Height(1);
    Display.putstr("Saving changes .....");
    displaySetpointsScreen();
    int ouputStreamLength = 0;
    String outputString;
    
    for (int arrayIndex = 0; arrayIndex < asize; arrayIndex++)
    {
    outputString += String(iSetpointParams[arrayIndex]);
    outputString += ",";
    }
    
    outputString += ",";
    ouputStreamLength = outputString.length();
    char cWriteData[ouputStreamLength];
    outputString.toCharArray(cWriteData, ouputStreamLength);
    
    if (Display.file_Exists(fileName))
    {
    Display.file_Erase(fileName);
    delay(100);
    }
    word iFile = Display.file_Open(fileName, 'w');
    Display.file_Write(ouputStreamLength, cWriteData, iFile);
    Display.file_Close(iFile);
    delay(2000);
    }
    Last edited by Frank B; 1 week ago.

    Comment


    • #3
      Thanks. I really appreciate the response. And I will give this a try.

      Comment

      Working...
      X