Waveshield won't play files ...plz help

hello everybody,

i have an problem with the waveshield for arduino.
the sketch on ladyada to play all files in root directory works fine.
now i want to build it in my own code which uses GPS data to figure out what file it should play…
but always i get only :"couldn’t open 2.wav or 6 or 7.wav… etc.
the files are used in void vergleich();

here is my code:

#include <string.h>
#include <ctype.h>
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"

 
  int ledpin = 13;     // LED test pin
  char speicher[80];
  char Breitengrad[10];
  char Laengengrad[11];
  char BG[13];
  char LG[14];
  char *ptr, *ptr2;
  float Bgrad, Lgrad;
  int i,x,y,z;
  
  
  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
  FatReader f;      // This holds the information for the file we're play

  WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time
 
  
  void setup(){
    
    pinMode(ledpin, OUTPUT);
    Serial.begin(9600);
    Serial1.begin(4800);
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT); 
  }
  
   void loop(){

    rechnen();
    if(z==1)
    {
    vergleich();
    z=0;
    }
   

   }



  void rechnen()
  {
    if(x==3)
    {
   double B=atof(Breitengrad);
    //Serial.println(B,DEC);
    double L=atof(Laengengrad);
    //Serial.println(L,DEC);
    
     Bgrad=(int(B / 100) + (B - (int(B / 100) * 100)) / 60);
     Lgrad=(int(L / 100) + (L - (int(L / 100) * 100)) / 60);
    //Serial.println(Bgrad,DEC);
    //Serial.println(Lgrad,DEC);
    x=0;
   y++;
    z++;
  }
  }
  
void vergleich()
{
  
  
  if(y==1)
  {
  
  if(Bgrad < 51.52019 && Bgrad > 51.51924 )
   {
     if(Lgrad < 7.48888 && Lgrad > 7.48838)
     {
     Serial.println("Klönnesstraße Ecke Hernebachstraße");
     playcomplete("15.WAV");
     }
     }

  if(Bgrad < 51.51972 && Bgrad > 51.51897 )
   {
     if(Lgrad < 7.48857 && Lgrad > 7.48785)
     {
     Serial.println("Klönnestraße an der Jet Tankstelle");
     playcomplete("16.WAV");
     }
     }

  if(Bgrad < 51.51897 && Bgrad > 51.51822 )
   {
     if(Lgrad < 7.48818 && Lgrad > 7.48755)
     {
     Serial.println("Klönnestraße Ecke Inselstraße");
     playcomplete("19.WAV");
     }
     }

  if(Bgrad < 51.51821 && Bgrad > 51.5176 )
   {
     if(Lgrad < 7.48794 && Lgrad > 7.48745)
     {
     Serial.println("Klönnestraße Kreuz Eisenachestraße/Hallesdestraße");
     playcomplete("20.WAV");
     }
     }

  if(Bgrad <51.51760 && Bgrad > 51.51693 )
   {
     if(Lgrad < 7.48793 && Lgrad > 7.48744)
     {
     Serial.println("Klönnestraße Ecke Heimbaustraße");
     playcomplete("18.WAV");
     }
     }

  if(Bgrad <51.51693 && Bgrad > 51.51636 )
   {
     if(Lgrad < 7.48799 && Lgrad > 7.4875)
     {
     Serial.println("Klönnestraße Ecke Güntherstraße");
     playcomplete("17.WAV");
     }
     }
 
  if(Bgrad < 51.5183 && Bgrad > 51.51793 )
   {
     if(Lgrad < 7.48759 && Lgrad > 7.4865)
     {
     Serial.println("Eisenacher Straße Ecke Klönnestraße");
     playcomplete("5.WAV");
     }
     }

   if(Bgrad < 51.51831 && Bgrad > 51.51752 )
   {
     if(Lgrad < 7.4865 && Lgrad > 7.48422)
     {
     Serial.println("Eisenacher Straße Mitte");
     playcomplete("6.WAV");
     }
     }

   if(Bgrad < 51.51766 && Bgrad > 51.51635 )
   {
     if(Lgrad < 7.48377 && Lgrad > 7.48235)
     {
     Serial.println("Eisenacher Straße Ecke Güntherstraße");
     playcomplete("4.WAV");
     }
     }  

   if(Bgrad < 51.52 && Bgrad > 51.51969 )
   {
     if(Lgrad < 7.48637 && Lgrad > 7.48482)
     {
     Serial.println("Körnebachstraße Ecke Inselstraße");
     playcomplete("21.WAV");
     }
     }  

  if(Bgrad < 51.52019 && Bgrad > 51.51986 )
   {
     if(Lgrad < 7.48774 && Lgrad > 7.48637)
     {
     Serial.println("Körnebachstraße Mitte");
     playcomplete("23.WAV");
     }
     }  

  if(Bgrad < 51.52034 && Bgrad > 51.52005 )
   {
     if(Lgrad < 7.48866 && Lgrad > 7.48774)
     {
     Serial.println("Körnebachstraße Ecke Klönnestraße");
     playcomplete("22.WAV");
     }
     }  

  if(Bgrad < 51.51969 && Bgrad > 51.5191 )
   {
     if(Lgrad < 7.48575 && Lgrad > 7.48483)
     {
     Serial.println("Inselstraße Ecke Körnebachstraße");
     playcomplete("14.WAV");
     }
     }  

  if(Bgrad < 51.51935 && Bgrad > 51.866 )
   {
     if(Lgrad < 7.48678 && Lgrad > 7.48575)
     {
     Serial.println("Inselstraße Mitte");
     playcomplete("29.WAV");
     }
     }  

  if(Bgrad < 51.51893 && Bgrad > 51.51826 )
   {
     if(Lgrad < 7.48759 && Lgrad > 7.48678)
     {
     Serial.println("Inselstraße Ecke Klönnestraße");
     playcomplete("13.WAV");
     }
     }  

  if(Bgrad <51.52151 && Bgrad > 51.52034 )
   {
     if(Lgrad < 7.48892 && Lgrad > 7.48819)
     {
     Serial.println("Im Spähenfelde Anfang Klönnestraße");
     playcomplete("12.WAV");
     }
     }  

  if(Bgrad <51.52268 && Bgrad >51.52151 )
   {
     if(Lgrad < 7.48872 && Lgrad > 7.48773)
     {
     Serial.println("Im Spähefelde Mitte");
     playcomplete("11.WAV");
     }
     }  

  if(Bgrad <51.5238 && Bgrad >51.52268 )
   {
     if(Lgrad < 7.48828 && Lgrad > 7.48647)
     {
     Serial.println("Im Spähefelde Ecke Brachder Straße");
     playcomplete("10.WAV");
     }
     }  

  if(Bgrad <51.51769 && Bgrad >51.51768 )
   {
     if(Lgrad < 7.49015 && Lgrad > 7.48944)
     {
     Serial.println("Lüneburgerstraße Ecke Güntherstraße");
     playcomplete("24.WAV");
     }
     }  

  if(Bgrad <51.52057 && Bgrad >51.51952 )
   {
     if(Lgrad < 7.49132 && Lgrad > 7.48946)
     {
     Serial.println("Zinkhüttenweg");
     playcomplete("27.WAV");
     }
     }  

  if(Bgrad < 51.51829 && Bgrad > 51.51796 )
   {
     if(Lgrad < 7.48879 && Lgrad > 7.48775)
     {
     Serial.println("Halleschestraße Ecke Klönnestraße");
     playcomplete("1.WAV");
     }
     }  

  if(Bgrad < 51.51827 && Bgrad > 51.51799 )
   {
     if(Lgrad < 7.49045 && Lgrad > 7.4888)
     {
     Serial.println("Halleschestraße Kreuz Lüneburgstraße");
     playcomplete("3.WAV");
     }
     }  

  if(Bgrad < 51.51819 && Bgrad > 51.51784 )
   {
     if(Lgrad < 7.49207 && Lgrad > 7.49045)
     {
     Serial.println("Halleschestraße Mitte");
     playcomplete("2.WAV");
     }
     }  

  if(Bgrad < 51.52029 && Bgrad > 51.51926 )
   {
     if(Lgrad < 7.48487 && Lgrad > 7.48322)
     {
     Serial.println("Westfalen Akademie Parkplatz");
     playcomplete("26.WAV");
     }
     }  

  if(Bgrad < 51.51742 && Bgrad > 51.51701 )
    {
      if(Lgrad < 7.48761 && Lgrad > 7.48652)
     {
     Serial.println("Heimbaustraße Ecke Klönnestraße");
     playcomplete("8.WAV");
     }
     }  

  if(Bgrad < 51.51741 && Bgrad > 51.51700 )
    {
      if(Lgrad < 7.48652 && Lgrad > 7.48544)
     {
     Serial.println("Heimbaustraße Mitte");
     playcomplete("9.WAV");
     }
     }  

  if(Bgrad < 51.51733 && Bgrad > 51.51699 )
    {
      if(Lgrad < 7.48544 && Lgrad > 7.48395)
     {
     Serial.println("Heimbaustraße Ecke Güntherstraße");
     playcomplete("7.WAV");
     }
     }  

  if(Bgrad < 51.51648 && Bgrad > 51.51614 )
    {
      if(Lgrad < 7.48767 && Lgrad >7.48631)
     {
     Serial.println("Günther Ecke Klönnestraße");
     playcomplete("28.WAV");
     }
     }  

  if(Bgrad < 51.51861 && Bgrad > 51.51769 )
    {
      if(Lgrad < 7.48981 && Lgrad >7.48923)
     {
     Serial.println("Lüneburgstraße Kreuz Halleschestraße");
     playcomplete("25.WAV");
     }
     }
    y=0;
  }
 else
{
 Serial.println("Signal out of Range...");
 delay(1000);
} 
}
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
  // now its done playing
}
void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
  
  // ok time to play! start playback
  wave.play();
}

hope someone could figure out where the problem is…
thx a lot 4 help
ben

     if(Lgrad < 7.48888 && Lgrad > 7.48838)

Wouldn’t

     if(Lgrad > 7.48838 && Lgrad < 7.48888)

make more sense?

What happens if Lgrad == 7.48838 or Lgrad == 7.48888?

but always i get only :"couldn’t open 2.wav or 6 or 7.wav… etc.

Are we supposed to know what is on your card? Case matters, if that makes any difference.

this are ranges and for the project it makes no sense ... it always go into the if() and print out the names but wont play the wave data... i dont understand why.....

it always go into the if() and print out the names but wont play the wave data... i dont understand why.....

Then,,, I would assume that the problem is that the names of the files actually on the SD card are not EXACTLY the same as the names you are using... Take the SD card out,,, and stick it in a PC,,, and list the files on the card... The answer will most likely become quite clear...

Are the multiple punctuation marks helping???

hehe i've heard about this mistake with incorrect names but i really type the same names :) aaahhhh :P my head burns °°

Take the SD card out,,, and stick it in a PC,,, and list the files on the card...

Prove it, just for me.

It is easy enough to modify the library, to add a Serial.print() statement to print out the EXACT name that is played, in the sketch that works. Then, modify this sketch to use EXACTLY the same name.

You might need to quote all of the space characters in the name:

"2 .WAV"

The SD card filenames are 8.3 format and the library may not handle matching a string that isn't already in 8.3 format. And get the case right.

so i’ve checked the data names and they equals to the names on sd card 1:1

the 8.3 format means that when u have names longer than 8 charakter it will be cut like MONOCHRO~.WAV (MONOCHRONICLE.WAV)

thx 4 replies :slight_smile:

i dont know what i could do to slove this problem…

I ran into this problem when working on my Kirk chair and found that I had to simplify the file names for the Wave Shield to find and play them. You might try renaming your files something like test1.wav, etc. and modifying your code accordingly to see if they will then play.

i have slove my problem :)

i used pin 13 for blink led but it was used in the waveshield too so the programm had no chance to play files ^^

thx a lot 4 your replies :)