The development environment is Arduino.
We had them run a program similar to the following, but after running rewindDirectory()
, we went through the file name acquisition for the second time.
Is there something wrong?
Or is it a phenomenon that depends on the SD card?
Please let me know.
Also, the number of files recognized is up to 9 (actually 13 files exist).
Is there a limit to the number of files?
//For SPRESENSE
# include <SDHCI.h>
SDClass SD;
constuint8_tcs_SD=5;
char Mp3Name [128];
File theSD;
File entry;
File root;
void setup()
{
intnk = 0;
Serial.begin (115200);
SD.begin();
// SD Card File Name Acquisition Experiment
root=SD.open("/");
while(true)
{
entry=root.openNextFile();
if(!entry)
{
// If there are no more files
root.rewindDirectory();
usleep(40000);
break;
}
// If it is not a directory name
if(!entry.isDirectory())
{
String fileName=entry.name();
strcpy(Mp3Name, & fileName[0]);
nk++;
printf("[%02d]%s\n", nk, Mp3Name);
}
}
nk = 0;
while(true)
{
entry=root.openNextFile();
if(!entry)
{
// If there are no more files
root.rewindDirectory();
usleep(40000);
break;
}
// If it is not a directory name
if(!entry.isDirectory())
{
String fileName=entry.name();
strcpy(Mp3Name, & fileName[0]);
nk++;
printf("[%02d]%s\n", nk, Mp3Name);
}
}
printf("SetupEnd\n";
}
void loop() {
// put your main code here, to run repeatly:
}
I've been into the same problem.
At the end of File entry=dir.openNextFile();
, close the file with entry.close();
.I'm sure you're stuck with the maximum number of files you can open (estimated)
I was wondering why SDHCI's sample sketch UsbMscAndFileOperation.ino works, and I noticed it while looking at the difference.
Try it.
//For SPRESENSE
# include <SDHCI.h>
SDClass SD;
constuint8_tcs_SD=5;
char Mp3Name [128];
File theSD;
File entry;
File root;
void setup()
{
intnk = 0;
Serial.begin (115200);
SD.begin();
// SD Card File Name Acquisition Experiment
root=SD.open("/");
while(true)
{
entry=root.openNextFile();
if(!entry)
{
// If there are no more files
root.rewindDirectory();
usleep(40000);
break;
}
// If it is not a directory name
if(!entry.isDirectory())
{
String fileName=entry.name();
strcpy(Mp3Name, & fileName[0]);
nk++;
printf("[%02d]%s\n", nk, Mp3Name);
}
entry.close();//★★Add★★
}
nk = 0;
while(true)
{
entry=root.openNextFile();
if(!entry)
{
// If there are no more files
root.rewindDirectory();
usleep(40000);
break;
}
// If it is not a directory name
if(!entry.isDirectory())
{
String fileName=entry.name();
strcpy(Mp3Name, & fileName[0]);
nk++;
printf("[%02d]%s\n", nk, Mp3Name);
}
entry.close();//★★Add★★
}
printf("SetupEnd\n";
}
void loop() {
// put your main code here, to run repeatly:
}
© 2024 OneMinuteCode. All rights reserved.