lerxstrulz
Well-known member
Hi,
I have a sketch that contains the ability to list all the files on the SD card (like the ListFiles example.) All of a sudden this is not working any longer. On the first iteration it is failing. HOWEVER, I can still read and write individual files on the SD Card.
I was thinking maybe it was a memory issue with my sketch, but even the simple program below is not working. It fails on the first call of dir.openNextFile(). Anyone have any ideas why this would just stop working, especially when I seem to be able to access the SD card just fine?
I'm using a Teensy 3.2 with the Audio Adaptor, Arduino IDE 1.6.8 and TeensyDuino 1.29.
Thanks in advance!
I have a sketch that contains the ability to list all the files on the SD card (like the ListFiles example.) All of a sudden this is not working any longer. On the first iteration it is failing. HOWEVER, I can still read and write individual files on the SD Card.
I was thinking maybe it was a memory issue with my sketch, but even the simple program below is not working. It fails on the first call of dir.openNextFile(). Anyone have any ideas why this would just stop working, especially when I seem to be able to access the SD card just fine?
I'm using a Teensy 3.2 with the Audio Adaptor, Arduino IDE 1.6.8 and TeensyDuino 1.29.
Thanks in advance!
Code:
#include <SPI.h>
#include <SD.h>
// These pins are for the Teensy Audio Adaptor SD Card reader - DO NOT CHANGE!
const int SDCARD_CS_PIN = 10;
const int SDCARD_MOSI_PIN = 7;
const int SDCARD_SCK_PIN = 14;
String listFiles(File dir)
{
while(true) {
File entry = dir.openNextFile();
if (! entry) {
Serial.println("NO MORE FILES!");
// no more files
break;
}
// convert to string to make it easier to work with...
String entryName = (String)entry.name();
Serial.println("FOUND: " + entryName);
entry.close();
}
}
/***
* Initial setup...runs only once when the board is turned on.
*/
void setup()
{
Serial.begin(57600);
delay(500);
// Check SD card
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
Serial.println("Unable to access the SD card");
} else {
// Read the contents of the SD card
File root = SD.open("/");
root.rewindDirectory();
listFiles(root);
root.close();
}
}
/***
* Main program loop
*/
void loop()
{
}
// END