Arduino Forum

Using Arduino => Storage => Topic started by: HF_ATL on Nov 07, 2018, 06:37 pm

Title: SD card writing issue
Post by: HF_ATL on Nov 07, 2018, 06:37 pm
Hello all,

I'd like to ask for help regarding an issue I'm having with SD card writing.

I'm writing 10 headings for each column with tabs ("\t") between them - such that after importing into excel via text file with tab delimited all headings sit correctly (one column for each).

The second line will be used for printing variable values when one of them change its value, and I want the first line to be always there.

I tried used SD.write and SD.append functions but the first one clears all data on the first line, second one add one line for each time that function is called in the code.

How can I adapt easily the functions to suit my needs?
Also any way to just change the specific column (each data variable) if for instance only one variable change and the others remain constant? Or better to write all of them as soon as one of them change?


I'm using a string for concatenate all the variables and all the headings, and then:

String headings = "Date\tHour\tCountry\tAge\........

writeFile(SD, "/data.txt",headings.c_str());

writeFile(SD, "/data.txt",variables.c_str());


Functions below:

void writeFile(fs::FS &fs, const char * path, const char * message){
    Serial.printf("Writing file: %s\r\n", path);

    File file = fs.open(path, FILE_WRITE);
    if(!file){
        Serial.println("- failed to open file for writing");
        return;
    }
    if(file.print(message)){
        Serial.println("- file written");
    } else {
        Serial.println("- frite failed");
    }
}

void appendFile(fs::FS &fs, const char * path, const char * message){
    Serial.printf("Appending to file: %s\r\n", path);

    File file = fs.open(path, FILE_APPEND);
    if(!file){
        Serial.println("- failed to open file for appending");
        return;
    }
    if(file.print(message)){
        Serial.println("- message appended");
    } else {
        Serial.println("- append failed");
    }
}




Many thanks!
Title: Re: SD card writing issue
Post by: Juraj on Nov 07, 2018, 07:39 pm
which library?
Title: Re: SD card writing issue
Post by: HF_ATL on Nov 07, 2018, 11:20 pm
Thanks for the reply.
It is this one... https://github.com/espressif/arduino-esp32/blob/master/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino
Title: Re: SD card writing issue
Post by: Juraj on Nov 08, 2018, 12:39 pm
SPIFFS is not for SD card. it is for internal flash memory file system
Title: Re: SD card writing issue
Post by: HF_ATL on Nov 08, 2018, 04:38 pm
Thanks for pointing that out, I'll look into others libraries...