Go Down

Topic: Create file and printDirectory on cycle. (Read 967 times) previous topic - next topic

carcharias

Hi, i have problem with function in cycle. This is my code:

Code: [Select]
#include <SD.h>

File root;

const int chipSelect = 4;   

void setup()
{
  Serial.begin(9600);

  pinMode(10, OUTPUT);
  if (!SD.begin(4)) {
    Serial.println("Failed to configure SD card");
    return;
  }
}

void loop()
{
  printDirectory();
  delay (3000);
  createfile("something.txt");
  delay(3000);
  printDirectory();
  delay (3000);
}

void printDirectory() {
  root = SD.open("/");
  while(true) {
     File entry =  root.openNextFile();
     if (! entry) {
       root.rewindDirectory();
       root.close();       
       break;
     }
     Serial.println(entry.name());
     entry.close();
   }

}

void createfile(char *myfile)
{
  Serial.println("file creating...");
  if (SD.exists(myfile)) {
    Serial.println("but exist.");
  }
  else {
    root = SD.open(myfile, FILE_WRITE);
    root.close();
    Serial.println("created.");
  }
}


So, when im start procces after reset, only first printDirectory on loop show file list on sd root corectly. After that i use createfile like second function on loop, then third printDirectory cant show file list. And after that all printDirectory cant show file list. In this case help only reset button. Can you help mi someone with this ? Thanks

fat16lib

There seems to be a lot of bugs in the Arduino 1.0 version of SD.h.  The listfiles example seems to have problems.  People also have reported problems with the Datalogger example.

Lots of people contact me since I wrote SdFat and SD.h is a wrapper for an old version of SdFat.

I had nothing to do with the SD.h wrapper and no longer support the version of SdFat that was use for SD.h.

Go Up