Go Down

Topic: EEPROM better than SD card for audio ? (Read 5511 times) previous topic - next topic


I have had one last try at using the SD card.

I modified the Adafruit wave library to take my bcd inputs, but its exactly the same, it reads the 256Mb cards, but not most of the 2Gb cards.

Heres the code  below, I dont know if there is something stupid, otherwise I will carry on with the eeprom try, which I am rather out of my depth on I must confess...

Code: [Select]

#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

int talkingPin = 19;  // high while audio playing to video chip to keep number on.
int aPin =18; //define pin numbers for bcd inputs from HT12D
int bPin =17;
int cPin =15;
int dPin =16;
int vtPin = 14; // define pin numbers for valid transmission input from HT12D
int track ; // define audio track number
int bcda ; // define bcd digitalreads for BCD/dec conversion
int bcdb;
int bcdc;
int bcdd;
int valid ;  // to be set high if vt in

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


void setup() {
  // set up serial port

  pinMode (aPin,INPUT);  //bcd inputs from HT12
  pinMode (bPin,INPUT);
  pinMode (cPin,INPUT);
  pinMode (dPin,INPUT);
  pinMode (vtPin,INPUT);  // valid trasnmission input
  pinMode (talkingPin,OUTPUT); // display enable to vga chip

  putstring_nl("WaveHC with 9 inputs");

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

   if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you  *****  TRIED BOTH
// if (!card.init()) {    //play with 8 MHz spi (default faster!)
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    while(1);     // then 'halt' - do nothing!
  // enable optimize read - some cards may timeout. Disable if you're having problems *** TRIED WITH AND WITHOUT AND true
// card.partialBlockRead(false);
  // 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.

void loop() {

  bcda = digitalRead ( aPin );  // read the state of the video micro "decode" data outputs 
  bcdb = digitalRead ( bPin );
  bcdc = digitalRead ( cPin );
  bcdd = digitalRead ( dPin );
  valid = digitalRead ( vtPin );  // check if signal received, set valid high

  if (bcda==1 && bcdb==0 && bcdc == 0 && bcdd == 0 ) { //longwinded bcd / dec decoding to give track number to be read
    track = 1;
  if (bcda==0 && bcdb==1 && bcdc == 0 && bcdd == 0 ) {
    track = 2;
  if (bcda==1 && bcdb==1 && bcdc == 0 && bcdd == 0 ) {
    track = 3;
  if (bcda==0 && bcdb==0 && bcdc == 1 && bcdd == 0 ) {
    track = 4;
  if (bcda==1 && bcdb==0 && bcdc == 1 && bcdd == 0 ) {
    track = 5;
  if (bcda==0 && bcdb==1 && bcdc == 1 && bcdd == 0 ) {
    track = 6;
  if (bcda==1 && bcdb==1 && bcdc == 1 && bcdd == 0 ) {
    track = 7;
  if (bcda==0 && bcdb==0 && bcdc == 0 && bcdd == 1 ) {
    track = 8;
  if (bcda==1 && bcdb==0 && bcdc == 0 && bcdd == 1 ) {
    track = 9;

// if ( valid == HIGH ){

  if (track==1 ) {
  if (track==2) {
  if (track==3) {
  if (track==4) {
  if (track==5) {
  if (track==6) {
  if (track==7) {
  if (track==8) {
  if (track==9) {
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  if (wave.isplaying) {//   set display enable high to vga chip
    digitalWrite(talkingPin, LOW);
    digitalWrite(talkingPin, HIGH);
  while (wave.isplaying) {

  // 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!  cant happen with talkinpin
//  wave.stop(); // stop it
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file ");
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV");
if (valid == 1){  //  wont run without this here
    // ok time to play! start playback




What is your hardware connection to the SD card?
Are you using an IC to buffer the signals from the Arduino to get them down to 3.3V levels?
How are you powering the SD card? They can be power hungry and need more than the 50mA an FTDI chip can put out, if that is your source for example.

I followed the design of this shield when I added parts for my Bobuino, and it works great with 2 GB cards.
I used a 74AC125D for the data buffer and IXF25001MEV33 for a 3.3V regulator.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Sep 25, 2011, 09:25 pm Last Edit: Sep 25, 2011, 09:36 pm by Boffin1 Reason: 1
This is really frustrating, I used the same circuit as you Bob, I made 4 of these units and they all have the same problem,  I have a separate 3.3v 150mA regulator, I scoped the output and its steady.  I tried a couple of different voltage buffer chips, I have decoupled everything.

Tomorrow I think I will make a separate part on perf/vero board, and try it with all the recommended part numbers if I can get them.

Have you tried yours playing back audio clips?   I can't see it making any difference, I dont think mine is even getting that far.

With it fitted to the board I have no serial to see whats happening.

I would like to go the DS cvard route, the eeprom is fiddly recording to.


I don't know enough about this to offer advice. But what i can say it that i bought a adafruit wave shield a few months ago and have been using a 2gig card with only a minor problem.  when i first got the card i put some files on it all was ok. I changed the files using a diffident computer and lynux instead of my windows. I then spent a whole day trying to get to the bottom of a intermittent sound output. For the first half of the day i put it down to another part of the project that i had just been working on, not the audio which i thought was working fine. i did do a quick check on the audio and it read the first file fine, so i put it down to some other change in the code. Anyway after lots of swearing and head scratching and taking the code back to a version from a week earlier i eventually found the sd card was doing all sorts of strange things. Sometimes recognized files sometimes didn't , sometimes player weird clicks instead of the audio. Took the card home reformatted put the original files on again using windows and it all worked again. It still worked fine now it's installed in a interactive display for kids and plays nature noises, had no problems since. Still don't know why it did it. I was planning on using a 32gb card for a new project so i hope it they do go above 250mb :)


I haven't done more than the SdFat provided tests.
I get Write & Read results of ~160K & 280K with a Sandisk Ultra 15 MB/s SDHC 16GB card on the Benchmark test.

"With it fitted to the board I have no serial to see whats happening."
Huh? What does the SPI to the SD card have to do with Serial out to a monitor?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


Sep 25, 2011, 09:58 pm Last Edit: Sep 25, 2011, 10:01 pm by Boffin1 Reason: 1
I meant that I cant see all the error reports that the sketch has when initiating the card.

Perhaps I will make up a test jig using the arduino board tomorrow so I can monitor everything



Thats the sort of problems I have been having with the SD cards,( in my project)  its only the smaller capacity cards that work consistantly, and there is a chance that I will have to make a load of these devices, so I have to get the sound stable , and if I use SD cards they must be current ones that I can buy.

That why I was thinking of using an eeprom, but its just a bit too confusing for my experience at the moment, so if I can get the card working it would be the best...........................


This is where GrayNomad's "perfect debugging tool"would come in handy!
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


I hav'nt heard of that, I will do a search...


There's a whole thread on it, a work in progress still.

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


very interesting, but way over my head at the moment  :-)


Before changing anything on my problem board, I checked the specs of my 3.3 v low drop out regulator, and it was rated at 100mA output.
I had 'scoped the 3v3 output and could not see any glitches ( but my junk usb scope has poor sync )

At that time, two of my  SD cards worked ( one 256Mb and one of the 2Gb microSD with adaptor )  , the other 2 ( 2 Gb ) could be read on the PC but wouldn't boot on the project.
In case the problem was a dip in the 3v3 when initialising the cards, I just tried putting a 1000mFd cap on the 3v3 line.

Then all 4 cards worked !   I thought I had it cracked, but when I removed the 1000mFd cap, all 4 still booted up OK !

I have since fitted the right type of buffer chip ( 74HC4050 ), and an 800 Ma low dropout regulator and all is still working.

I have since thought that the problem might be something to do with the fact that the audio control micro is triggered from the video control micro,  it might be that the one is trying to trigger the other as soon as it comes on, so I am going to try a delay in the setup function of the video control micro to give the other one a chance to initiate the SD card.

Meanwhile I will still experiment with the mysterious eeprom route  just in case  !

Another mystery is that I have another 4 faulty SD micro cards that had failed in these projects, and they wont even format or be read on a PC ??


Have you seen the APR9600 IC? Sounds like it is a full solution for your requirements in just one IC.


That chip is the same as the ISD chips that I used several years back, the quality is not too good when played through a decent amp .

If I dont come right by the end of the week I might have to go back to that :-)


I used a 74AC125D for the data buffer and IXF25001MEV33 for a 3.3V regulator.

Do you have the datasheet for IXF25001MEV33? (google returns only one reference to this part, your spreadsheet).

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131