Is this a bug or what? I can't get this code to run that used to work fine.

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. :fearful:

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

First, why the delay? That means the pin has to stay HIGH for half a second or you may not notice it.

Second:

   else 

      while(digitalRead(triggerPin)==LOW) 
    {
      delay(500); 
    }


    {
      // Aha! we found a file that isnt a directory
      putstring("Playing ");

It looks to me like you have braces in the wrong place. What is the second opening brace for? Is it supposed to be part of the "if"?

Maybe:

   else 
    {
      // wait for button press
      while(digitalRead(triggerPin)==LOW) 
         { }

      delay (100);  // debounce

      // Aha! we found a file that isnt a directory
      putstring("Playing ");

It's being triggered from a second arduino board so keeping the pin HIGH for even a few seconds is not a problem. I'm an artist first and electronics dabbler second so some of my ways may seem odd to you pros out there.

I changed that line in the sketch just for the heck of it but I'm still not getting the file to play, just the long weird serial monitor info every time the input pin goes HIGH.

list recursively - possible stack overflow if subdirectories too nested

That's a very telling comment.

tatticus:
Possibly something in the new Arduino IDE has raised a bug?

Try an older version of the IDE, I'm not familiar with the wave library. However AWOL could well be right. Try an SD card with only a couple of files on it.

That's the aggravating part. I've tried reformatting the card and just putting 2 .wav files on it and the only difference is the long list of weird numbers in the serial monitor is simply a shorter list of weird numbers and again, no sounds are played.

I'd hate to go all the way back to a pre- Arduino 1.0 IDE but if there are no other options I don't know what else to do.

Actaully going all the way back to Arduino 0023 I'm still not getting anything to play just this in the monitor everytime the pin goes HIGH.

Wave test!
Free RAM: 672
Using partition 1, type is FAT16
Files found:
_~1.TRA
99.WAV
TRASHE~1/
SPOTLI~1/
  STORE-V1/
    VOLUME~1.PLI
    STORES/
      CEB09F~1/
        PSID.DB
        INDEXS~1
        0~1.IND
        0~1.SHA
        0~2.IND
        0~3.IND
        0~2.SHA
        0~4.IND
        0~5.IND
        0~6.IND
        0~7.IND
        0~8.IND
        0~9.IND
        PERMST~1
        LIVE0~1.SHA
        STORE.DB
        STORE~1.DB
        JOURNA~1
        JOURNA~2
        JOURNA~3
        LIVE0~5.IND
        LIVE0~2.SHA
        LIVE0~1.IND
        LIVE0~3.SHA
        LIVE0~4.SHA
        LIVE0~5.SHA
        STORE~1.UPD
        LIVE0~4.IND
        LIVE0~8.IND
        LIVE0~7.SHA
        LIVE0~9.IND
        LIVE0~10.IND
        LIVE0~7.IND
        LIVE0~11.IND
        LIVE0~2.IND
        LIVE0~3.IND
        LIVE0~6.IND
        LIVE0~6.SHA
_99~1.WAV
98.WAV
_98~1.WAV
97.WAV
_97~1.WAV
96.WAV
_96~1.WAV
95.WAV
_95~1.WAV
94.WAV
_94~1.WAV
93.WAV
_93~1.WAV
92.WAV
_92~1.WAV
91.WAV
_91~1.WAV
90.WAV
_90~1.WAV
9.WAV
_9~1.WAV
89.WAV
_89~1.WAV
88.WAV
_88~1.WAV
87.WAV
_87~1.WAV
59.WAV
_59~1.WAV
58.WAV
_58~1.WAV
57.WAV
_57~1.WAV
56.WAV
_56~1.WAV
55.WAV
_55~1.WAV
54.WAV
_54~1.WAV
53.WAV
_53~1.WAV
52.WAV
_52~1.WAV
51.WAV
_51~1.WAV
50.WAV
_50~1.WAV
5.WAV
_5~1.WAV
49.WAV
_49~1.WAV
48.WAV
_48~1.WAV
47.WAV
_47~1.WAV
46.WAV
_46~1.WAV
45.WAV
_45~1.WAV
44.WAV
_44~1.WAV
43.WAV
_43~1.WAV
42.WAV
_42~1.WAV
41.WAV
_41~1.WAV
86.WAV
_86~1.WAV
85.WAV
_85~1.WAV
84.WAV
_84~1.WAV
83.WAV
_83~1.WAV
82.WAV
_82~1.WAV
81.WAV
_81~1.WAV
102.WAV
_102~1.WAV
68.WAV
_68~1.WAV
67.WAV
_67~1.WAV
66.WAV
_66~1.WAV
65.WAV
_65~1.WAV
64.WAV
_64~1.WAV
63.WAV
_63~1.WAV
145.WAV
_145~1.WAV
144.WAV
_144~1.WAV
143.WAV
_143~1.WAV
142.WAV
_142~1.WAV
141.WAV
_141~1.WAV
107.WAV
_107~1.WAV
62.WAV
_62~1.WAV
61.WAV
_61~1.WAV
60.WAV
_60~1.WAV
6.WAV
_6~1.WAV
80.WAV
_80~1.WAV
8.WAV
_8~1.WAV
79.WAV
_79~1.WAV
78.WAV
_78~1.WAV
77.WAV
_77~1.WAV
103.WAV
_103~1.WAV
110.WAV
_110~1.WAV
109.WAV
_109~1.WAV
11.WAV
_11~1.WAV
112.WAV
_112~1.WAV
140.WAV
_140~1.WAV
14.WAV
_14~1.WAV
111.WAV
_111~1.WAV
108.WAV
_108~1.WAV
100.WAV
_100~1.WAV
1.WAV
_1~1.WAV
10.WAV
_10~1.WAV
106.WAV
_106~1.WAV
116.WAV
_116~1.WAV
115.WAV
_115~1.WAV
104.WAV
_104~1.WAV
118.WAV
_118~1.WAV
117.WAV
_117~1.WAV
105.WAV
_105~1.WAV
33.WAV
_33~1.WAV
32.WAV
_32~1.WAV
31.WAV
_31~1.WAV
30.WAV
_30~1.WAV
3.WAV
_3~1.WAV
29.WAV
_29~1.WAV
28.WAV
_28~1.WAV
27.WAV
_27~1.WAV
26.WAV
_26~1.WAV
25.WAV
_25~1.WAV
24.WAV
_24~1.WAV
23.WAV
_23~1.WAV
21.WAV
_21~1.WAV
20.WAV
_20~1.WAV
2.WAV
_2~1.WAV
19.WAV
_19~1.WAV
18.WAV
_18~1.WAV
17.WAV
_17~1.WAV
16.WAV
_16~1.WAV
15.WAV
_15~1.WAV
147.WAV
_147~1.WAV
146.WAV
_146~1.WAV
40.WAV
_40~1.WAV
4.WAV
_4~1.WAV
39.WAV
_39~1.WAV
38.WAV
_38~1.WAV
37.WAV
_37~1.WAV
36.WAV
_36~1.WAV
35.WAV
_35~1.WAV
34.WAV
_34~1.WAV
101.WAV
_101~1.WAV
139.WAV
_139~1.WAV
138.WAV
_138~1.WAV
137.WAV
_137~1.WAV
136.WAV
_136~1.WAV
135.WAV
_135~1.WAV
134.WAV
_134~1.WAV
133.WAV
_133~1.WAV
132.WAV
_132~1.WAV
131.WAV
_131~1.WAV
130.WAV
_130~1.WAV
13.WAV
_13~1.WAV
129.WAV
_129~1.WAV
128.WAV
_128~1.WAV
127.WAV
_127~1.WAV
126.WAV
_126~1.WAV
22.WAV
_22~1.WAV
125.WAV
_125~1.WAV
124.WAV
_124~1.WAV
123.WAV
_123~1.WAV
122.WAV
_122~1.WAV
121.WAV
_121~1.WAV
120.WAV
_120~1.WAV
12.WAV
_12~1.WAV
119.WAV
_119~1.WAV
114.WAV
_114~1.WAV
113.WAV
_113~1.WAV
76.WAV
_76~1.WAV
75.WAV
_75~1.WAV
74.WAV
_74~1.WAV
73.WAV
_73~1.WAV
72.WAV
_72~1.WAV
71.WAV
_71~1.WAV
70.WAV
_70~1.WAV
7.WAV
_7~1.WAV
69.WAV
_69~1.WAV
Files found:
_~1.TRA
99.WAV
TRASHE~1/
SPOTLI~1/
  STORE-V1/
    VOLUME~1.PLI
    STORES/
      CEB09F~1/
        PSID.DB
        INDEXS~1
        0~1.IND
        0~1.SHA
        0~2.IND
        0~3.IND
        0~2.SHA
        0~4.IND
        0~5.IND
        0~6.IND
        0~7.IND
        0~8.IND
        0~9.IND
        PERMST~1
        LIVE0~1.SHA
        STORE.DB
        STORE~1.DB
        JOURNA~1
        JOURNA~2
        JOURNA~3
        LIVE0~5.IND
        LIVE0~2.SHA
        LIVE0~1.IND
        LIVE0~3.SHA
        LIVE0~4.SHA
        LIVE0~5.SHA
        STORE~1.UPD
        LIVE0~4.IND
        LIVE0~8.IND
        LIVE0~7.SHA
        LIVE0~9.IND
        LIVE0~10.IND
        LIVE0~7.IND
        LIVE0~11.IND
        LIVE0~2.IND
        LIVE0~3.IND
        LIVE0~6.IND
        LIVE0~6.SHA
_99~1.WAV
98.WAV
_98~1.WAV
97.WAV
_97~1.WAV
96.WAV
_96~1.WAV
95.WAV
_95~1.WAV
94.WAV
_94~1.WAV
93.WAV
_93~1.WAV
92.WAV
_92~1.WAV
91.WAV
_91~1.WAV
90.WAV
_90~1.WAV
9.WAV
_9~1.WAV
89.WAV
_89~1.WAV
88.WAV
_88~1.WAV
87.WAV
_87~1.WAV
59.WAV
_59~1.WAV
58.WAV
_58~1.WAV
57.WAV
_57~1.WAV
56.WAV
_56~1.WAV
55.WAV
_55~1.WAV
54.WAV
_54~1.WAV
53.WAV
_53~1.WAV
52.WAV
_52~1.WAV
51.WAV
_51~1.WAV
50.WAV
_50~1.WAV
5.WAV
_5~1.WAV
49.WAV
_49~1.WAV
48.WAV
_48~1.WAV
47.WAV
_47~1.WAV
46.WAV
_46~1.WAV
45.WAV
_45~1.WAV
44.WAV
_44~1.WAV
43.WAV
_43~1.WAV
42.WAV
_42~1.WAV
41.WAV
_41~1.WAV
86.WAV
_86~1.WAV
85.WAV
_85~1.WAV
84.WAV
_84~1.WAV
83.WAV
_83~1.WAV
82.WAV
_82~1.WAV
81.WAV
_81~1.WAV
102.WAV
_102~1.WAV
68.WAV
_68~1.WAV
67.WAV
_67~1.WAV
66.WAV
_66~1.WAV
65.WAV
_65~1.WAV
64.WAV
_64~1.WAV
63.WAV
_63~1.WAV
145.WAV
_145~1.WAV
144.WAV
_144~1.WAV
143.WAV
_143~1.WAV
142.WAV
_142~1.WAV
141.WAV
_141~1.WAV
107.WAV
_107~1.WAV
62.WAV
_62~1.WAV
61.WAV
_61~1.WAV
60.WAV
_60~1.WAV
6.WAV
_6~1.WAV
80.WAV
_80~1.WAV
8.WAV
_8~1.WAV
79.WAV
_79~1.WAV
78.WAV
_78~1.WAV
77.WAV
_77~1.WAV
103.WAV
_103~1.WAV
110.WAV
_110~1.WAV
109.WAV
_109~1.WAV
11.WAV
_11~1.WAV
112.WAV
_112~1.WAV
140.WAV
_140~1.WAV
14.WAV
_14~1.WAV
111.WAV
_111~1.WAV
108.WAV
_108~1.WAV
100.WAV
_100~1.WAV
1.WAV
_1~1.WAV
10.WAV
_10~1.WAV
106.WAV
_106~1.WAV
116.WAV
_116~1.WAV
115.WAV
_115~1.WAV
104.WAV
_104~1.WAV
118.WAV
_118~1.WAV
117.WAV
_117~1.WAV
105.WAV
_105~1.WAV
33.WAV
_33~1.WAV
32.WAV
_32~1.WAV
31.WAV
_31~1.WAV
30.WAV
_30~1.WAV
3.WAV
_3~1.WAV
29.WAV
_29~1.WAV
28.WAV
_28~1.WAV
27.WAV
_27~1.WAV
26.WAV
_26~1.WAV
25.WAV
_25~1.WAV
24.WAV
_24~1.WAV
23.WAV
_23~1.WAV
21.WAV
_21~1.WAV
20.WAV
_20~1.WAV
2.WAV
_2~1.WAV
19.WAV
_19~1.WAV
18.WAV
_18~1.WAV
17.WAV
_17~1.WAV
16.WAV
_16~1.WAV
15.WAV
_15~1.WAV
147.WAV
_147~1.WAV
146.WAV
_146~1.WAV
40.WAV
_40~1.WAV
4.WAV
_4~1.WAV
39.WAV
_39~1.WAV
38.WAV
_38~1.WAV
37.WAV
_37~1.WAV
36.WAV
_36~1.WAV
35.WAV
_35~1.WAV
34.WAV
_34~1.WAV
101.WAV
_101~1.WAV
139.WAV
_139~1.WAV
138.WAV
_138~1.WAV
137.WAV
_137~1.WAV
136.WAV
_136~1.WAV
135.WAV
_135~1.WAV
134.WAV
_134~1.WAV
133.WAV
_133~1.WAV
132.WAV
_132~1.WAV
131.WAV
_131~1.WAV
130.WAV
_130~1.WAV
13.WAV
_13~1.WAV
129.WAV
_129~1.WAV
128.WAV
_128~1.WAV
127.WAV
_127~1.WAV
126.WAV
_126~1.WAV
22.WAV
_22~1.WAV
125.WAV
_125~1.WAV
124.WAV
_124~1.WAV
123.WAV
_123~1.WAV
122.WAV
_122~1.WAV
121.WAV
_121~1.WAV
120.WAV
_120~1.WAV
12.WAV
_12~1.WAV
119.WAV
_119~1.WAV
114.WAV
_114~1.WAV
113.WAV
_113~1.WAV
76.WAV
_76~1.WAV
75.WAV
_75~1.WAV
74.WAV
_74~1.WAV
73.WAV
_73~1.WAV
72.WAV
_72~1.WAV
71.WAV
_71~1.WAV
70.WAV
_70~1.WAV
7.WAV
_7~1.WAV
69.WAV
_69~1.WAV

That doesn't look like two files to me.

Correct, that's the card test with all 130+ files on it. I meant to say in a previous test I ran it with only a few files (after a fresh format) and still no sounds would play, just the odd string of numbers.

The numbers you're seeing are the ascii codes of the characters in the file names. (848265 comes from 84='T', 82='R', 65='A' etc).

The behaviour of the print/write functions changed when Arduino V1 was released and perhaps this is causing the output formatting problem.

If it's supposed to be playing a sound and isn't, that is probably a separate problem. In that case I suggest you put the existing card aside and start with the simplest case of one file containing a valid sound and see whether the sound file is listed, recognised and played correctly. In your original test data there seem to be a tone of files which are not sound files and I have no idea which ones you're trying to play.

Good call on the ASCII PeterH. That explains what I'm seeing! Hopefully this bug gets squashed in an upcoming IDE.