WaveShield Project Help?

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
greiter
 
Posts: 3
Joined: Sun Nov 13, 2011 3:33 pm

WaveShield Project Help?

Post by greiter »

I wasnt sure to post this in the arduino page or the shield page.

I am working on a project and am admittedly novice to arduino programming and have run out of ideas with a little problem I am having.

I am trying to interface my arduino and waveshield with some equipment in a museum I work for. They used to use crestron processors to communicate with a BANNED player via RS232 then play a track on the BANNED. The BANNED players have since stopped working and I would like to replace these with Arduinos to cut down on moving parts.

The commands that the processor issues to the BANNED player are:

"?C" What track are you currently playing? It expects a reply of two digits with a carriage return
CHXXSL play this chapter where XX is the chapter number. It expects a reply of an R with a carriage return

I am trying to get the arduino to reply with "01" to when it receives "?" over the serial port and play track T1.WAV when it receives "1" etc.

The problem I am having is that the arduino will only play T6.WAV correctly, It plays when it receives the command and restarts when I send the command again. It will do it for no other tracks. I think it probably has something to do with DEC to ASCII or however the arduino reads the command and the command for number 6 just happens to work.

Any ideas? Thanks for any help you can give.
Geoff

Here is the code I am using that only works properly for playing T6.WAV:

Code: Select all

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


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

#define DEBOUNCE 100  // button debouncer

int incomingByte = 0;
// 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; 
} 

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);
}

void setup() {
  // set up serial port
  Serial.begin(4800);
  putstring_nl("WaveHC with 6 buttons");
  
   putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
  
  //  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("Ready!");
}

void loop() {
  //putstring(".");            // uncomment this to see if the loop isnt running
  {
    
  if (Serial.available() > 0) { 
    incomingByte = Serial.read();
 
 if (incomingByte == 63)
     Serial.println('01');
 
  if (incomingByte == '1')
     playfile("T1.WAV");
   
  if (incomingByte == '2')
      playfile("T2.WAV");
      
  if (incomingByte == '3')
      playfile("T3.WAV");
   
  if (incomingByte == '4')
      playfile("T4.WAV");
      
  if (incomingByte == '5')
      playfile("T5.WAV");
      
   if (incomingByte == '6')
      playfile("T6.WAV");  
}
}

Serial.flush();

}


// Plays a full file from beginning to end with no pause.
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();
  Serial.print('R');
}

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: WaveShield Project Help?

Post by adafruit_support_bill »

I am trying to get the arduino to reply with "01" to when it receives "?" over the serial port
You need to use double quotes here then:

Code: Select all

    if (incomingByte == 63)
         Serial.println('01');
The problem I am having is that the arduino will only play T6.WAV correctly
It would help to look at the diagnostic output.
Are you sure it is getting the characters you think it is getting? Add some print statements to echo the input.
Are you sure that all the .WAV files exist? You should see file error messages if they do not.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”