Hello. I am working on a project that involves an Ultra Sonic sensor and the Adafruit Music Maker MP3 Shield. I have code working to trigger audio playback from stored files on an SD card, but there is an issue where the code is reading files that don't exist, and at times is calling these files for playback and nothing is happening.
I have tried to take things back a step and use basic Arduino code to read an SD card and list the files.
/*
Listfiles
This example shows how print out the files in a
directory on a SD card
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
modified 2 Feb 2014
by Scott Fitzgerald
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File root;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
root = SD.open("/");
printDirectory(root, 0);
Serial.println("done!");
}
void loop() {
// nothing happens after setup finishes.
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
And my serial monitor is looking like this..
Initializing SD card...initialization done.
SPOTLI~1/
STORE-V2/
00A22E~1/
PSID.DB 8192
TM~1.LIO 0
LIO~1.CRE 0
TMP.CAB 0
CA~1.CRE 0
INDEXS~1 28
~1.IND 4096
~~2.IND 16
~~~3.IND 8
~~~~4.IND 3277
~~~~~5.IND 4096
~~~~~~31.IND 440
~~~~~~34.IND 4096
~~~~~~37.IND 440
~~~~~~40.IND 2056
~~~~~~43.IND 8
~~~~~~46.IND 1088
~~~~~~48.IND 13
~1.DIR 65536
LIVE~1.IND 4096
LIVE~~2.IND 32768
LIVE~~~3.IND 16384
LIVE~~~4.IND 3277
LIVE~~~5.IND 4096
LIVE~~69.IND 8192
LIVE~~72.IND 4096
LIVE~~75.IND 8192
LIVE~~78.IND 8224
LIVE~~81.IND 1024
LIVE~~85.IND 65536
LIVE~~88.IND 6519
LIVE~1.DIR 65536
STORE.DB 118784
STOR~1.DB 118784
REVERS~1 65536
TMPSPO~1.STA 4096
STORE_~1 4
JOURNA~1.COR/
JOURNA~1.LIV/
JOURNA~2.LIV/
JOURNA~3.LIV/
JOURNA~4.LIV/
JOURNA~1.ASS/
JOURNA~2.ASS/
JOURNA~1.HEA/
JOURNA~1.MIG/
JOURNA~2.MIG/
JOURNA~1 0
JOURNA~1.SCA/
SHUTDO~1 4
JOURNA~1.2 140
REVERS~1.SHA 3136
~1.SHA 4096
STOR~1.UPD 12
0DIREC~1.SHA 1088
~~~~~174.SHA 2
LIVE~1.SHA 4096
LIVE~~2.SHA 464
LIVE~~~3.SHA 0
LIVE~~~4.SHA 8
LIVE~~~5.SHA 2056
LIVE~195.SHA 65536
LIVE0D~1.SHA 1088
LIVE~202.SHA 3
REVERS~1.UPD 2
TMPSPO~1.LOC 4190
VOLUME~1.PLI 4315
FSEVEN~1/
FSEVEN~1 36
000000~1 230
000000~2 71
TRACK001.AAC 25248
_TRACK~1.AAC 4096
TRACK002.AAC 32086
_TRACK~2.AAC 4096
TRACK003.AAC 26826
_TRACK~3.AAC 4096
TRACK004.AAC 27878
_TRACK~4.AAC 4096
TRACK005.AAC 23933
_TRACK~5.AAC 4096
TRACK006.AAC 23933
_TRAC~33.AAC 4096
TRACK007.AAC 29719
_TRAC~37.AAC 4096
TRACK008.AAC 40239
_TRAC~41.AAC 4096
TRACK009.AAC 28404
_TRAC~45.AAC 4096
TRACK010.AAC 24722
_TRAC~49.AAC 4096
TRACK011.AAC 22618
_TRAC~53.AAC 4096
done!
The files are all named track001 and so on. I have reformatted the card using the suggested programme on the forum homepage here. You can see in the serial monitor that it is calling files that don't exist such as _TRACK~1.AAC. It seems to be making a duplicate of each sound file, and each one is tagged with a number of 4096, but I don't know what these numbers represent? I also don't know what the FSEVEN~1 represents and that is sometimes called for playback when the sensor is triggered.
I have tried moving the files into their own directory but it is making no difference. Does anyone know why this is happening? Is there a way to exclude these names from the "playlist"?