Skip to main content
added 143 characters in body
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

You need to open the file in append mode:

SD.open("file.txt", O_RDWR | O_APPEND);

It depends on the file being there. If it fails to open because the file isn't there you can open it in "create" mode instead:

SD.open("file.txt", O_RDWR | O_CREAT);

For example:

// Try and append
File f = SD.open("file.txt", O_RDWR | O_APPEND);
if (!f) {
    // It failed, so try and make a new file.
    f = SD.open("file.txt", O_RDWR | O_CREAT);
    if (!f) {
        // It failed too, so give up.
        Serial.println("Failed to open file.txt");
    }
} 

// Only write to the file if the file is actually open.
if (f) {
    f.print(/* your data here */)
    f.close();
}

You need to open the file in append mode:

SD.open("file.txt", O_RDWR | O_APPEND);

It depends on the file being there. If it fails to open because the file isn't there you can open it in "create" mode instead:

SD.open("file.txt", O_RDWR | O_CREAT);

For example:

// Try and append
File f = SD.open("file.txt", O_RDWR | O_APPEND);
if (!f) {
    // It failed, so try and make a new file.
    f = SD.open("file.txt", O_RDWR | O_CREAT);
    if (!f) {
        // It failed too, so give up.
        Serial.println("Failed to open file.txt");
    }
}

You need to open the file in append mode:

SD.open("file.txt", O_RDWR | O_APPEND);

It depends on the file being there. If it fails to open because the file isn't there you can open it in "create" mode instead:

SD.open("file.txt", O_RDWR | O_CREAT);

For example:

// Try and append
File f = SD.open("file.txt", O_RDWR | O_APPEND);
if (!f) {
    // It failed, so try and make a new file.
    f = SD.open("file.txt", O_RDWR | O_CREAT);
    if (!f) {
        // It failed too, so give up.
        Serial.println("Failed to open file.txt");
    }
} 

// Only write to the file if the file is actually open.
if (f) {
    f.print(/* your data here */)
    f.close();
}
added 347 characters in body
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

You need to open the file in append mode:

SD.open("file.txt", O_RDWR | O_APPEND);

It depends on the file being there. If it fails to open because the file isn't there you can open it in "create" mode instead:

SD.open("file.txt", O_RDWR | O_CREAT);

For example:

// Try and append
File f = SD.open("file.txt", O_RDWR | O_APPEND);
if (!f) {
    // It failed, so try and make a new file.
    f = SD.open("file.txt", O_RDWR | O_CREAT);
    if (!f) {
        // It failed too, so give up.
        Serial.println("Failed to open file.txt");
    }
}

You need to open the file in append mode:

SD.open("file.txt", O_RDWR | O_APPEND);

It depends on the file being there. If it fails to open because the file isn't there you can open it in "create" mode instead:

SD.open("file.txt", O_RDWR | O_CREAT);

You need to open the file in append mode:

SD.open("file.txt", O_RDWR | O_APPEND);

It depends on the file being there. If it fails to open because the file isn't there you can open it in "create" mode instead:

SD.open("file.txt", O_RDWR | O_CREAT);

For example:

// Try and append
File f = SD.open("file.txt", O_RDWR | O_APPEND);
if (!f) {
    // It failed, so try and make a new file.
    f = SD.open("file.txt", O_RDWR | O_CREAT);
    if (!f) {
        // It failed too, so give up.
        Serial.println("Failed to open file.txt");
    }
}
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

You need to open the file in append mode:

SD.open("file.txt", O_RDWR | O_APPEND);

It depends on the file being there. If it fails to open because the file isn't there you can open it in "create" mode instead:

SD.open("file.txt", O_RDWR | O_CREAT);