After a sleepless night and long day struggling with this I've come to beg for some help. I'm honestly at wits end here. This project is almost done and I must ship it this week so I'm obviously stressing out big time here. ANY help would be more appreciated than you know.
I've used a handful of these waveshields http://www.adafruit.com/products/94on projects but haven't seen this issue before. I simply want to play one of 146 sounds (named 1.wav, 2.wav, etc.) everytime a pin is triggered HIGH. I've done this project before (using the exact same sound files in fact). Possibly something in the new Arduino IDE has raised a bug?
This should be simple, I'm using almost stock code from an example sketch on adafruit's website, the only real change being this line where the board waits for a HIGH trigger from another Arduino board
while(digitalRead(triggerPin)==LOW)
{
delay(500);
}
Serial monitor is showing a bunch of nonsense though, no file names and no sound playing when pin7 goes HIGH.
This is my sketch
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
const int triggerPin = 7; //
SdReader card;Â Â // This object holds the information for the card
FatVolume vol;Â Â // This holds the information for the partition on the card
FatReader root;Â // This holds the information for the filesystem on the card
uint8_t dirLevel; // indent level for file/dir names  (for prettyprinting)
dir_t dirBuf;Â Â // buffer for directory reads
WaveHC wave;Â Â Â // This is the only wave (audio) object, since we will only play one at a time
// Function definitions (we define them here, but the code is below)
void lsR(FatReader &d);
void play(FatReader &dir);
void setup() {
 Serial.begin(9600);     // set up Serial library at 9600 bps for debugging
Â
 putstring_nl("\nWave test!"); // say we woke up!
Â
 putstring("Free RAM: ");   // This can help with debugging, running out of RAM is bad
 Serial.println(freeRam());Â
 // Set the output pins for the DAC control. This pins are defined in the library
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(7, INPUT);
Â
 // if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
 if (!card.init()) {    //play with 8 MHz spi (default faster!)Â
  putstring_nl("Card init. failed!"); // Something went wrong, lets print out why
  sdErrorCheck();
  while(1);              // then 'halt' - do nothing!
 }
Â
 // enable optimize read - some cards may timeout. Disable if you're having problems
 card.partialBlockRead(true);
Â
 // Now we will look for a FAT partition!
 uint8_t part;
 for (part = 0; part < 5; part++) {  // we have up to 5 slots to look in
  if (vol.init(card, part))
   break;              // we found one, lets bail
 }
 if (part == 5) {           // if we ended up not finding one :(
  putstring_nl("No valid FAT partition!");
  sdErrorCheck();   // Something went wrong, lets print out why
  while(1);              // then 'halt' - do nothing!
 }
Â
 // Lets tell the user about what we found
 putstring("Using partition ");
 Serial.print(part, DEC);
 putstring(", type is FAT");
 Serial.println(vol.fatType(),DEC);  // FAT16 or FAT32?
Â
 // Try to open the root directory
 if (!root.openRoot(vol)) {
  putstring_nl("Can't open root dir!"); // Something went wrong,
  while(1);              // then 'halt' - do nothing!
 }
Â
 // Whew! We got past the tough parts.
 putstring_nl("Files found:");
 dirLevel = 0;
 // Print out all of the files in all the directories.
 lsR(root);
}
//////////////////////////////////// LOOP
void loop() {
 root.rewind();
 play(root);
}
/////////////////////////////////// HELPERS
// this handy function will return the number of bytes currently free in RAM, great for debugging!Â
int freeRam(void)
{
 extern int __bss_end;
 extern int *__brkval;
 int free_memory;
 if((int)__brkval == 0) {
  free_memory = ((int)&free_memory) - ((int)&__bss_end);
 }
 else {
  free_memory = ((int)&free_memory) - ((int)__brkval);
 }
 return free_memory;
}
/*
* print error message and halt if SD I/O error, great for debugging!
*/
void sdErrorCheck(void)
{
 if (!card.errorCode()) return;
 putstring("\n\rSD I/O error: ");
 Serial.print(card.errorCode(), HEX);
 putstring(", ");
 Serial.println(card.errorData(), HEX);
 while(1);
}
/*
* print dir_t name field. The output is 8.3 format, so like SOUND.WAV or FILENAME.DAT
*/
void printName(dir_t &dir)
{
 for (uint8_t i = 0; i < 11; i++) {  // 8.3 format has 8+3 = 11 letters in it
  if (dir.name[i] == ' ')
    continue;    // dont print any spaces in the name
  if (i == 8)
    Serial.print('.');     // after the 8th letter, place a dot
  Serial.print(dir.name[i]);   // print the n'th digit
 }
 if (DIR_IS_SUBDIR(dir))
  Serial.print('/');   // directories get a / at the end
}
/*
* list recursively - possible stack overflow if subdirectories too nested
*/
void lsR(FatReader &d)
{
 int8_t r;          // indicates the level of recursion
Â
 while ((r = d.readDir(dirBuf)) > 0) {  // read the next file in the directory
  // skip subdirs . and ..
  if (dirBuf.name[0] == '.')
   continue;
 Â
  for (uint8_t i = 0; i < dirLevel; i++)
   Serial.print(' ');    // this is for prettyprinting, put spaces in front
  printName(dirBuf);     // print the name of the file we just found
  Serial.println();     // and a new line
 Â
  if (DIR_IS_SUBDIR(dirBuf)) { // we will recurse on any direcory
   FatReader s;        // make a new directory object to hold information
   dirLevel += 2;       // indent 2 spaces for future prints
   if (s.open(vol, dirBuf))
    lsR(s);          // list all the files in this directory now!
   dirLevel -=2;        // remove the extra indentation
  }
 }
 sdErrorCheck();         // are we doign OK?
}
/*
* play recursively - possible stack overflow if subdirectories too nested
*/
void play(FatReader &dir)
{
 FatReader file;
 while (dir.readDir(dirBuf) > 0) {  // Read every file in the directory one at a time
  // skip . and .. directories
  if (dirBuf.name[0] == '.')
   continue;
 Â
  Serial.println();      // clear out a new line
 Â
  for (uint8_t i = 0; i < dirLevel; i++)
   Serial.print(' ');   // this is for prettyprinting, put spaces in front
  if (!file.open(vol, dirBuf)) {   // open the file in the directory
   Serial.println("file.open failed"); // something went wrong :(
   while(1);              // halt
  }
 Â
  if (file.isDir()) {          // check if we opened a new directory
   putstring("Subdir: ");
   printName(dirBuf);
   dirLevel += 2;           // add more spaces
   // play files in subdirectory
   play(file);            // recursive!
   dirLevel -= 2; Â
  }
  else
 Â
  while(digitalRead(triggerPin)==LOW)
  {
   delay(500);
  }
 Â
 Â
   {
   // Aha! we found a file that isnt a directory
    putstring("Playing "); printName(dirBuf);   // print it out
   if (!wave.create(file)) {      // Figure out, is it a WAV proper?
    putstring(" Not a valid WAV");  // ok skip it
   } else {
    Serial.println();         // Hooray it IS a WAV proper!
    wave.play();           // make some noise!
  Â
    while (wave.isplaying) {     // playing occurs in interrupts, so we print dots in realtime
     putstring(".");
     delay(100);
    }
    sdErrorCheck();          // everything OK?
//Â Â Â Â if (wave.errors)Serial.println(wave.errors);Â Â // wave decoding errors
   }
  }
 }
}
This is what serial monitor is showing every time the trigger pin goes high!
5012649.8÷
Wave test!
Free RAM: 655
Using partition 1, type is FAT16
Files found:
9512649.848265
5757.876586
84826583726912649/
83807984767312649/
 8384798269458649/
  86797685776912649.807673
  838479826983/
   67696648577012649/
    80837368.6866
    73786869888312649
    4812649.737868
    4812649.837265
    4812650.737868
    4812651.737868
    4812650.837265
    4812652.737868
    4812653.737868
    4812654.737868
    4812655.737868
    4812656.737868
    4812657.737868
    80698277838412649
    767386694812649.837265
    8384798269.6866
    838479826912649.6866
    74798582786512649
    74798582786512650
    74798582786512651
    767386694812653.737868
95575712649.876586
5756.876586
95575612649.876586
5755.876586
95575512649.876586
5754.876586
95575412649.876586
5753.876586