Go Down

Topic: SD Filenames (Read 604 times) previous topic - next topic

tfoote

I keep getting errors when I use SD.mkdir. This is my code:
Code: [Select]
if(char(serialReceived) == '\n') {
        Serial.print("MKDIR: ");
        Serial.println(serialCommand);
        Serial.println(serialCommand.length());
        char sen[serialCommand.length()+1];
        for(int i = 0; i < serialCommand.length(); i++) {
          sen[i] = serialCommand.charAt(i);
        }
        if(SD.mkdir(sen)) {
          Serial.write(6);
        } else {
          Serial.write(21);
        }
        serialState = 0;
        serialCommand = "";
      } else {
        serialCommand += char(serialReceived);
      }


When I run this code, I get that SD.mkdir(sen) returns false.

el_supremo

You need to store a null at the end of the string. Try this:
Code: [Select]

        int i;
        for(i = 0; i < serialCommand.length(); i++) {
          sen[i] = serialCommand.charAt(i);
        }
        sen[i] = 0;


You should also make sure that the names you use are valid.
Pete

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy