FAT32/SDHC library for Wave and other shields
Moderators: adafruit_support_bill, adafruit

Re: FAT32/SDHC library for Wave and other shields

by LiveRock on Thu May 21, 2009 12:14 am

Hi

I have finished all the soldering. Created a sample file using AT&T speech engine, copied it into the SDHC card.
I managed to compiled all the sample sketches but there are no sound at all using the headphones...

Also, I see that that are many debug statements like

if (!card.init_card()) {
putstring_nl("Card init. failed!"); return;
}

If there is an error, where can I see it? Is there a window where all debug statement are displayed?

Thanks!
LiveRock
 
Posts: 26
Joined: Sun May 17, 2009 10:33 pm

Re: FAT32/SDHC library for Wave and other shields

by LiveRock on Thu May 21, 2009 12:48 am

Found out the problem.... even with the 74HC4050 hack, the wave shield does not support FAT32 as was my SDHC card.
I used another normal SD card 1G and format it using FAT and samples work great!!
LiveRock
 
Posts: 26
Joined: Sun May 17, 2009 10:33 pm

Re: FAT32/SDHC library for Wave and other shields

by zachtos on Fri May 22, 2009 6:39 pm

well, I figured out the proper code to get this to work. I don't know why it seemed so difficult. I'll post this in case there is another programming newbie out there trying to figure out how to call out files.

One more question, do I need to do anything special if I format my card to fat32 instead of fat16 w/ this library? I don't see anywhere that it need to tell it what FAT I'm using?

*** I love the pause/resume, it makes my sound files sound so smooth now when firing the rifle, taking hits or gaining upgrades!

Code: Select all | TOGGLE FULL SIZE
// this is the minimal working code to add audio to a project.  This code library will allow you to pause and resume waves, and allow fat32 file format


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

char fire[] = "RIFLE.WAV";
char shotty[] = "SHOTGUN.WAV";

SdReader card;
FatVolume vol;
FatReader root;
FatReader f;
WaveHC wave;      // only one!


void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Ready");

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  if (!card.init()) {
    putstring_nl("Card init. failed!");
    return;
  }
  if (!vol.init(card)) {
    putstring_nl("No partition!");
    return;
  }
  if (!root.openRoot(vol)) {
    putstring_nl("Couldn't open dir");
    return;
  }

  //putstring_nl("Files found:");

}


void loop()
{

  playfile(shotty);
  delay(10);
  wave.pause();
  delay(60);
  wave.resume();
  delay(2000);
  playfile(fire);
  delay(2000);  // if next wave starts, it will just skip it all together w/o some form of delay (IE, take hit will over-rite any other sounds etc
}


void playfile(char *name) {
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
 
  }
  if (!f.open(root, name)) {
    putstring("Couldn't open file ");
    Serial.print(name);
    return;
  }
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV");
    return;
  }
  // ok time to play!
  wave.play();
}
zachtos
 
Posts: 77
Joined: Sun May 03, 2009 8:18 pm

Re: FAT32/SDHC library for Wave and other shields

by fat16lib on Fri May 22, 2009 9:28 pm

LiveRock,

You have used 3.3 from the Arduino pin. Not all versions of the Arduino supply 3.3 volts.

I used 3.3 from the supply on the Wave shield. This is better since it works with all versions of the Arduino.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: FAT32/SDHC library for Wave and other shields

by fat16lib on Fri May 22, 2009 9:33 pm

zachtos,

WaveHC works with both FAT16 and FAT32 format SDs. You don't need to change your program to use FAT32.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: FAT32/SDHC library for Wave and other shields

by zachtos on Sat May 23, 2009 1:49 am

huh, I could not get the program to run after formatting the card to FAT32, it seems to work just fine on FAT16 though. I have not had much luck getting the waveshield to work while reading pulseIn() nor sending microdelay functions out to pulse an IR LED while waves are playing. I have to pause them to get accurate reads unless I can get a new idea... I may have to just build integrated sound boards to play sounds instead of wasting operations on the waveshield.
zachtos
 
Posts: 77
Joined: Sun May 03, 2009 8:18 pm

Re: FAT32/SDHC library for Wave and other shields

by fat16lib on Sat May 23, 2009 8:43 am

zachtos,

If you have problems with a FAT32 formatted SD, run SdReadTest.pde. It should give info about what is wrong.

I don't think you will be able get your pulseIn() or pulses to an IR LED to work while a wave file is playing. There can be delays of 10 to 20 ms while the SD is read. Also the DAC interrupts takes many microseconds and occur at the WAV sample rate.

I thought you were going to pause the WAV player while you did time critical operations.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: FAT32/SDHC library for Wave and other shields

by zachtos on Sat May 23, 2009 10:36 am

Correct, it works fine if I pause wave files while sending IR data and waiting for IR data. The problem is that the device is pretty much constantly waiting for IR data (it only sends out IR data about 60ms pulses x 4-5 times / second). But it reads pulseIn() for pretty much the entire duration outside of that (so you can take hits inbetween gun shots).... SOOooo, my gun sounds are basically being paused constantly. If the wave could play and not destroy pulseIn() reads, then this would work perfectly. Unless there is something I do not understand about pulseIn() or how the waveshield disrupts timing???

I am calling pulseIn(sensorPin, LOW, 150) // 150ms gives the sensor enough timeout time so it doesnt timeout while waiting for a data transmission, it seems to miss many shots if I go lower on the time out....

Also, I am sending the IR pulse 3 X per shot because they never seem to register only 20% of the time if I just send the pulse once, but if I loop it 3 times every button push, it works great. (IE, you dont want to be a sniper and have your shots only hit 20% of the time, but it's less noticibale if you are a fully auto gun)...

I can not get waves to resume smoothly either when exiting the pulseIn() function, they seem to *click* as soon as it resumes, which ruins the sound effect.

Perhaps all these timing critical things are just not compatible w/ a waveshield? I thought about calling pulseIn() as an interupt, but I could not get it to work properly, and I think the waveshield used all the interupt ports (pin 2,3)...

Maybe I should just use integrated sound chips where I send a few bits high on the D/I outs to call a wave play, that would not affect sounds at all, but I would not be able to resume file playbacks? or have any idea where to start looking for a ISD chip or pre-built circuit if there are cheap ones available?
zachtos
 
Posts: 77
Joined: Sun May 03, 2009 8:18 pm

Re: FAT32/SDHC library for Wave and other shields

by LiveRock on Sun May 24, 2009 9:50 pm

HI fat16lib, ok, I got it. I didn't know the waveshield also supply 3.3 V and was just thinking that I should trace the 3.3 V from the Ardunino itself.

Anyway, great work!

It works great but I do not know how to use your new library to take advantage of new features. It works with old ada waveshield library without problems.

One thing I need help is that I need to get waveshield and some form of ethernetshield to work together. I bought the neuelectronics etherhshield but I think there are conflicts in using the SPI. They couldn't work together; I wonder if someone would come up with a library to make that work together....
LiveRock
 
Posts: 26
Joined: Sun May 17, 2009 10:33 pm

Re: FAT32/SDHC library for Wave and other shields

by Algolosaur on Wed Jun 03, 2009 4:50 am

I suppose I should add my two cents here.

I ran the card test test program on the collection of odd cards I was able to scrape up, and can add as apparently working:
PNY OPTIMA SD 60X 2GB
Memorex 1GB SD
and apparently failing with an unmodified Wave Shield:
LEXAR SD 1GB Premium 60x
COBY mini 1 GB (used with adapter)

I also wish to note that running PiSpeak with a Memorex 1GB SD is currently causing loss of sound on the "four"s with no reported error when run using USB power from a Power Mac G5, but not when run using a 9V battery and disconnected from the USB cable.

Do the other SD card kits (GPS shield, FuzeBox) have the same problems?

Algolosaur
Veritas Vos Fugere Facet
Algolosaur
 
Posts: 67
Joined: Sun Apr 05, 2009 11:29 am
Location: Butler PA

Re: FAT32/SDHC library for Wave and other shields

by adafruit on Wed Jun 03, 2009 12:17 pm

what do you mean 'loss of sound'?
User avatar
adafruit
 
Posts: 11746
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: FAT32/SDHC library for Wave and other shields

by Algolosaur on Thu Jun 04, 2009 11:26 am

I would hear "three" "point" "one" "one" "five" on the speaker. The serial terminal showed the 4 file and reported no error, and there was no noticeable skip or pause.

My assumption is that the file was being mis-read, perhaps as having a duration of zero.

Unplugging the USB cable and plugging in a 9V battery produced the "three" "point" "one" "four" "one" "five" ... expected.

Other cards had produced similar dropped digits, with and without errors on the serial terminal. Those cards tested bad. I do not recall if the actual Memorex card with the skipped fours was tested.

Algolosaur
Veritas Vos Fugere Facet
Algolosaur
 
Posts: 67
Joined: Sun Apr 05, 2009 11:29 am
Location: Butler PA

Re: FAT32/SDHC library for Wave and other shields

by adafruit on Thu Jun 04, 2009 1:25 pm

that is fantastically bizarre
User avatar
adafruit
 
Posts: 11746
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: FAT32/SDHC library for Wave and other shields

by eti on Fri Jun 05, 2009 7:14 am

Hi all,
I've just built a GPS logger kit. The GPS part works well but not the SD card.
I have a Duemilanove with atmel 328p and a 64MB DaneElec SD card.

First, I tried with the "AF_SDLog" library with "GPSLogger_v2.pde" sketch and I only get some "card init failed".
The SD card works well on my laptop and has been formated as mentioned.

Secondly I've tested the "wavehc" library from http://forums.ladyada.net/viewtopic.php?f=31&t=8738.
The simple test sketch give me :
Code: Select all | TOGGLE FULL SIZE
init time: 40

Card type: SD1
readCID failedSD error
errorCode: 8
errorData: 0


What can I do now for make it work? Could you help me please?
thank you and sorry for my english
eti
 
Posts: 3
Joined: Fri Jun 05, 2009 6:51 am

Re: FAT32/SDHC library for Wave and other shields

by adafruit on Fri Jun 05, 2009 12:42 pm

try a different card. that card may just not work!
User avatar
adafruit
 
Posts: 11746
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc