Go Down

Topic: SD card writing issue (Read 98 times) previous topic - next topic

HF_ATL

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!

Juraj

You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

HF_ATL

Thanks for the reply.
It is this one... https://github.com/espressif/arduino-esp32/blob/master/libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino

Juraj

#3
Nov 08, 2018, 12:39 pm Last Edit: Nov 08, 2018, 04:56 pm by Juraj
SPIFFS is not for SD card. it is for internal flash memory file system
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

HF_ATL

Thanks for pointing that out, I'll look into others libraries...

Go Up