문제

I'm having some troubles with my Arduino. I'm trying to make a dynamic name for my file and transform it to char array like I saw on some post from this website.

Here's how I wrote my function:

void writeSD()
{ 
  DateTime dt = RTC.now();

  String temp = "DIVE";
  temp += dt.day();
  temp += dt.month();
  temp += dt.year();
  temp += ".txt";

  Serial.println(temp);

  char filename[temp.length()+1];
  temp.toCharArray(filename, sizeof(filename));
  myFile = SD.open(filename, FILE_WRITE);  

  if (myFile) {
    Serial.print("Writing to txt file...");
    myFile.print(dt.day(), DEC);
    myFile.print('-');
    myFile.print(dt.month(), DEC);
    myFile.print('-');
    myFile.print(dt.year(), DEC);
    myFile.print(' ');
    myFile.print(dt.hour(), DEC);
    myFile.print(':');
    myFile.print(dt.minute(), DEC);
    myFile.print(':');
    myFile.print(dt.second(), DEC);
    myFile.println();
    myFile.close();
    Serial.println("done.");
  } else {
    Serial.println("error opening txt file");
  }
}

I'm only having "error opening txt file" and I don't know why. The name of my file is correct and appears like this when I print it on the console : DIVE652014.TXT

도움이 되었습니까?

해결책

I figured out why that wasn't working when I read more precisely the documentation about the SD breakout board from Adafruit :

The SD card library does not support 'long filenames' such as we are used to. Instead, it uses the 8.3 format for file names, so keep file names short! For example IMAGE.JPG is fine, and datalog.txt is fine by "My GPS log file.text" is not!

So I had 10 chars but it only accepts 8 chars in the filename.

Thanks for trying to help me ! :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top