I've been trying to have 2 files to save data to on an SD card so I needed to create 2 .txt files. The library examples used test.txt and that worked for me, and on a couple occasions (with no edits to my code) other file names would work.
Simply substituting a different name into the library code causes it to fail at this point.
With this code, substituting test.txt would be recognized.
Note- I am using an Arduino Uno and an adafruit Rev B datalogger (newer version) Overview | Adafruit Data Logger Shield | Adafruit Learning System
#include <SPI.h>
#include <SD.h>
File myFile;
const int chipSelect = 10;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
pinMode(SS, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
if (SD.exists("thisPartHere.txt")) {
Serial.println("thisPartHere.txt exists.");
}
else {
Serial.println("thisPartHere.txt doesn't exist.");
}
// open a new file and immediately close it:
Serial.println("Creating thisPartHere.txt...");
myFile = SD.open("thisPartHere.txt", FILE_WRITE);
SD.open("thisPartHere.txt", FILE_WRITE);
myFile.close();
// Check to see if the file exists:
if (SD.exists("thisPartHere.txt")) {
Serial.println("thisPartHere.txt exists.");
}
else {
Serial.println("thisPartHere.txt doesn't exist.");
}
Serial port will print this:
Initializing SD card...initialization done.
thisPartHere.txt doesn't exist.
Creating thisPartHere.txt...
thisPartHere.txt doesn't exist.