Unable to play wav file after xbee able to communicate

07 Dec 2011

Hello guys, I was doing an project using 2 xbee to communicate with each other and once they are able to communicate, they would play a wav file. However I encountered a problem which is that the xbee is able to communicate with each other, but the wave file are not be able to play. Hope you guys can help me!

Here is my programming:

//Programming for XBEE//

#include "mbed.h"
#include "SDFileSystem.h"
#include "wave_player.h"

Serial xbee1(p9, p10);  //Creates a variable for serial comunication through pin 9 and 10
DigitalOut rst1(p11);   //Digital reset for the XBee, 200ns for reset
DigitalOut myled(LED1); //Create variable for Led 1 on the mbed
DigitalOut myled1(LED2);//Create variable for Led 2 on the mbed

SDFileSystem sd(p5, p6, p7, p8, "sd");
AnalogOut       DACout(p18);
wave_player     waver(&DACout);


int main()

{

     int req ;

     
     mkdir("/sd/wf/", 0777);     // make the directory to the SD card

                                // 0777 is the default mode so to have the widest access 

     FILE  *fp0   = fopen("/sd/wf/1.wav", "r"); 

     FILE  *fp1   = fopen("/sd/wf/2.wav", "r"); 

     FILE  *fp2   = fopen("/sd/wf/3.wav", "r"); 

     FILE  *fp3   = fopen("/sd/wf/4.wav", "r"); 

     FILE  *fp4   = fopen("/sd/wf/5.wav", "r"); 

     FILE  *fp5   = fopen("/sd/wf/6.wav", "r"); 

     FILE  *fp6   = fopen("/sd/wf/7.wav", "r"); 

     FILE  *fp7   = fopen("/sd/wf/8.wav", "r"); 

     FILE  *fp8   = fopen("/sd/wf/9.wav", "r"); 

     FILE  *fp9   = fopen("/sd/wf/10.wav", "r"); 

     FILE  *fp10  = fopen("/sd/wf/11.wav", "r"); 

     FILE  *fp11  = fopen("/sd/wf/12.wav", "r"); 

     FILE  *fp12  = fopen("/sd/wf/13.wav", "r"); 

     FILE  *fp13  = fopen("/sd/wf/14.wav", "r"); 

     FILE  *fp14  = fopen("/sd/wf/15.wav", "r"); 

     FILE  *fp15  = fopen("/sd/wf/16.wav", "r"); 

     FILE  *fp16  = fopen("/sd/wf/17.wav", "r"); 

     FILE  *fp17  = fopen("/sd/wf/18.wav", "r"); 

     FILE  *fp18  = fopen("/sd/wf/19.wav", "r"); 

     FILE  *fp19  = fopen("/sd/wf/20.wav", "r"); 

     FILE  *fp20  = fopen("/sd/wf/30.wav", "r"); 

     FILE  *fp21  = fopen("/sd/wf/40.wav", "r"); 

     FILE  *fp22  = fopen("/sd/wf/50.wav", "r"); 

     FILE  *fp23  = fopen("/sd/wf/60.wav", "r"); 

     FILE  *fp24  = fopen("/sd/wf/70.wav", "r"); 

     FILE  *fp25  = fopen("/sd/wf/80.wav", "r"); 

     FILE  *fp26  = fopen("/sd/wf/90.wav", "r"); 

     FILE  *fp27  = fopen("/sd/wf/Bus.wav", "r"); 

     FILE  *fp28  = fopen("/sd/wf/is approaching.wav", "r"); 

     rst1   = 0; //Set reset pin to 0

     myled  = 0;//Set LED1 to 0

     myled1 = 0;//Set LED2 to 0

     wait_ms(1);//Wait at least one millisecond

     rst1   = 1;//Set reset pin to 1

     wait_ms(1);//Wait another millisecond

 

   if(fp1 == NULL){

    printf("File couldn't open\n");

    }

 

  while (1)

  {

    if (xbee1.readable())

    {

      req = xbee1.getc();

      printf("%c\n", req);

      if (req == 'r') 

      xbee1.printf("100\n");

      waver.play(fp27);

    

      waver.play(fp9);

      waver.play(fp28);

      fseek(fp27,  0, SEEK_SET);  // set file poiter to beginning

      fseek(fp9, 0, SEEK_SET); 

      fseek(fp28, 0, SEEK_SET); 

      wait(1);

    }
  }
}
06 Dec 2011

Using code tags helps a lot.

Why are you creating the folder wf? Why not just open the files from the folder?

Lerche

07 Dec 2011

Sorry to ask but what is code tag?

Erm I create a folder wf is because as you can see, I have a lot of file to be played so I was thinking to collate it into a folder to have a better organization.

07 Dec 2011

You found the code tags ;-)

But why create, if the files are already in the folder? Why not open those files?

08 Dec 2011

Ok I shall give it a try. I was thinking could it be that I had open too many file causing the mbed to not able to play?

08 Dec 2011

Hello christian, I am able to play all the file already! thanks a lot! really appreciate all of your help man! (:

26 Nov 2013

Hi Daryl Tan Wei Guang, I am using the above code to play wav files after xbee communication but not even a sigle file is played. Can you please guide how you resolved this issue?

Moomal