Pages: [1]   Go Down
Author Topic: Create file and printDirectory on cycle.  (Read 936 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#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
Logged

0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1634
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: