I had existing code using and older version of the SdFat library that worked fine and now it has stopped working after installing the newest version (20131225) . IDE version 1.0.5.
Essentially I am trying to create a file called PLAYLIST.TXT that contains the names of all the other files on the SD card. This is done using the openNext() function. PLAYLIST.TXT is created on the SD card but openNext() does not find any files.
I tried the openNext() example from the library and it worked ok, listing all the files. I modified the same example to just open the playlist file and then close it, and it also does not find the files (just prints out 'Done!' with no files listed) - listing below. Commenting out the playlist file handling in my code also results in the file names being listed.
Anyone seen this change of behaviour and is there workaround?
/*
* Open all files in the root dir and print their filename and modify date/time
*/
#include <SdFat.h>
// SD chip select pin
const uint8_t chipSelect = SS;
// file system object
SdFat sd;
SdFile file;
SdFile myfile; // <<-- my mod
// define a serial output stream
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
while (!Serial) {} // wait for Leonardo
delay(1000);
// initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
// breadboards. use SPI_FULL_SPEED for better performance.
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
myfile.open("PLAYLIST.TXT", O_CREAT|O_WRITE); // <<-- my mod
// open next file in root. The volume working directory, vwd, is root
while (file.openNext(sd.vwd(), O_READ)) {
file.printName(&Serial);
cout << ' ';
file.printModifyDateTime(&Serial);
cout << endl;
file.close();
}
cout << "\nDone!" << endl;
myfile.close(); // <<-- my mod
}
//------------------------------------------------------------------------------
void loop() {}