Help with wave shield

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

Moderators: adafruit_support_bill, adafruit

Help with wave shield

Postby zaidhorse » Thu May 03, 2012 10:52 pm

So I, along with friends, have been working on a code for an arduino with a wave shield so that it captures a name of a file from serial and plugs it into the function playfile(). I know the part which captures the name of the file works. The problem is that whenever the arduino with the wave shield gets the file name through serial it prints "couldn't open file ----" (the hyphens replaced with the name of the file with the extension .wav). I even tried to take out the whole serial part and just run playfile() on a wave file that is already on the sdcard. same error. I am sure the files are on the sdcard and they are formatted properly has i got the files from the tutorial for the wave shield.
My code:

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

// 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(9600);
  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!
 
  // 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);

  // pin13 LED
  pinMode(13, OUTPUT);

  // enable pull-up resistors on switch pins (analog inputs)
  digitalWrite(14, HIGH);
  digitalWrite(15, HIGH);
  digitalWrite(16, HIGH);
  digitalWrite(17, HIGH);
  digitalWrite(18, HIGH);
  digitalWrite(19, HIGH);

  //  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() {
  char message[16];

  while (Serial.available() <2)
  {
  }
  for(int j = 0; j < 17; j++)
  {
    message[j] = '\0';
  }
  char ch = Serial.read();
  for(int i = 0; i < 16 && ch != '!' ; i++, ch = Serial.read())
  {

    message[i] = ch;
    while (Serial.available() <1)
    {
    }
  }
  playfile(message);
}




// 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();
}
zaidhorse
 
Posts: 8
Joined: Thu May 03, 2012 10:42 pm

Re: Help with wave shield

Postby adafruit_support_bill » Fri May 04, 2012 4:46 am

What OS are you using & how did you format the card?
Post the complete output from the serial monitor. Do you see any error from the card init in setup?
User avatar
adafruit_support_bill
 
Posts: 15898
Joined: Sat Feb 07, 2009 9:11 am

Re: Help with wave shield

Postby zaidhorse » Fri May 04, 2012 12:59 pm

we used ubuntu's disk utility to format the sdcard first FAT16 and then FAT32. Both didn't work. There are no errors beside "Couldn't Open file"
zaidhorse
 
Posts: 8
Joined: Thu May 03, 2012 10:42 pm

Re: Help with wave shield

Postby adafruit_support_bill » Fri May 04, 2012 1:38 pm

What is the name of the file you are trying to open? The SD library only supports the original FAT 8.3 file-naming convention. Files with names longer than that can't be opened.
User avatar
adafruit_support_bill
 
Posts: 15898
Joined: Sat Feb 07, 2009 9:11 am

Re: Help with wave shield

Postby zaidhorse » Fri May 04, 2012 4:04 pm

the name of the file is 12 digits and then the extension. What is the limit of file names with FAT 8.3? Is there any way around this?
zaidhorse
 
Posts: 8
Joined: Thu May 03, 2012 10:42 pm

Re: Help with wave shield

Postby adafruit_support_bill » Sun May 06, 2012 4:48 am

8.3 means 8 characters with a 3 character extension. Due to limited space on the Arduino platform, long filenames are not supported.
User avatar
adafruit_support_bill
 
Posts: 15898
Joined: Sat Feb 07, 2009 9:11 am


Return to Arduino Shields from Adafruit

Who is online

Users browsing this forum: No registered users and 8 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [105]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]