Wave Shield, Mega2560 and DaneElec 2gig SD

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
User avatar
miax
 
Posts: 157
Joined: Tue Apr 05, 2011 11:41 am

Wave Shield, Mega2560 and DaneElec 2gig SD

Post by miax »

I recently purchased several Wave 1.1 shields from the store and am having some problems with the SD Cards... I'm using the supplied SD card with the Music pack (2.0 Gig DANE-Elec) and the Arduino Mega 2560. I read through the pinned threads on SD card problems, and downloaded/tried the Panasonic SD formatter that worked for some folks. I'm also using the WaveHC libraries and example code from the tutorial page.

First I tried all the different options using the Panasonic SD format tool, and tried 3 different DaneElec SD cards - all failed on the same error. To make sure I wasn't mad I soldered-up a 2nd wave shield and did so very carefully, ultimately with the same results. I tried using FAT and FAT32 formats as well.

Next I tried editing SdReader.h and changing the SPI_INIT_SLOW line to #define SPI_INIT_SLOW 1 (per the ReadMe file with the wave shield). I saved this file, closed the Arduino editor and re-opened, re-compiled and re-loaded - with the same results.

The error codes I get are:

Wave test!
Free RAM: 6376
Error: Card init. failed!
SD I/O error: 1, 0

and

Wave test!
Free RAM: 6376
Error: Card init. failed!
SD I/O error: 1, FF

I get the "FF" instead of the "0" if I use the full/long format (OverWrite/Full) in the Panasonic program. Windows 7 and all other options produces the first result.

The example code I'm using is "daphc.pde" (from the WaveHC example libraries). The code has not been modified:

Code: Select all

/*
 * This example plays every .WAV file it finds on the SD card in a loop
 */
#include "WaveHC.h"
#include "WaveUtil.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 volumes root directory
WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

uint8_t dirLevel; // indent level for file/dir names    (for prettyprinting)
dir_t dirBuf;     // buffer for directory reads


/*
 * Define macro to put error messages in flash memory
 */
#define error(msg) error_P(PSTR(msg))

// Function definitions (we define them here, but the code is below)
void play(FatReader &dir);

//////////////////////////////////// SETUP
void setup() 
{
  Serial.begin(9600);           // set up Serial library at 9600 bps for debugging
  
  putstring_nl("\nWave test!");  // say we woke up!
  
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(FreeRam());

  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!)  
    error("Card init. failed!");  // Something went wrong, lets print out why
  }
  
  // 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  :(
    error("No valid FAT partition!");  // Something went wrong, lets print out why
  }
  
  // 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)) {
    error("Can't open root dir!");      // Something went wrong,
  }
  
  // Whew! We got past the tough parts.
  putstring_nl("Files found (* = fragmented):");

  // Print out all of the files in all the directories.
  root.ls(LS_R | LS_FLAG_FRAGMENTED);
}

//////////////////////////////////// LOOP
void loop() 
{ 
  root.rewind();
  play(root);
}

/////////////////////////////////// HELPERS
/*
 * print error message and halt
 */
void error_P(const char *str)
{
  PgmPrint("Error: ");
  SerialPrint_P(str);
  sdErrorCheck();
  while(1);
}
/*
 * print error message and halt if SD I/O error, great for debugging!
 */
void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  PgmPrint("\r\nSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  PgmPrint(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}
/*
 * play recursively - possible stack overflow if subdirectories too nested
 */
void play(FatReader &dir)
{
  FatReader file;
  while (dir.readDir(dirBuf) > 0) {    // Read every file in the directory one at a time
  
    // Skip it if not a subdirectory and not a .WAV file
    if (!DIR_IS_SUBDIR(dirBuf)
         && strncmp_P((char *)&dirBuf.name[8], PSTR("WAV"), 3)) {
      continue;
    }

    Serial.println();            // clear out a new line
    
    for (uint8_t i = 0; i < dirLevel; i++) {
       Serial.print(' ');       // this is for prettyprinting, put spaces in front
    }
    if (!file.open(vol, dirBuf)) {        // open the file in the directory
      error("file.open failed");          // something went wrong
    }
    
    if (file.isDir()) {                   // check if we opened a new directory
      putstring("Subdir: ");
      printEntryName(dirBuf);
      dirLevel += 2;                      // add more spaces
      // play files in subdirectory
      play(file);                         // recursive!
      dirLevel -= 2;    
    }
    else {
      // Aha! we found a file that isnt a directory
      putstring("Playing ");
      printEntryName(dirBuf);              // print it out
      if (!wave.create(file)) {            // Figure out, is it a WAV proper?
        putstring(" Not a valid WAV");     // ok skip it
      } else {
        Serial.println();                  // Hooray it IS a WAV proper!
        wave.play();                       // make some noise!
        
        uint8_t n = 0;
        while (wave.isplaying) {// playing occurs in interrupts, so we print dots in realtime
          putstring(".");
          if (!(++n % 32))Serial.println();
          delay(100);
        }       
        sdErrorCheck();                    // everything OK?
        // if (wave.errors)Serial.println(wave.errors);     // wave decoding errors
      }
    }
  }
}
Lastly here are some screen-caps of my newbie soldering for one of the shields, to make sure I didn't screw this up too!
Front shot of my newbie soldering
Front shot of my newbie soldering
WaveShield_Front.JPG (704.63 KiB) Viewed 2192 times
Back shot of my newbie soldering
Back shot of my newbie soldering
WaveShield_Back.JPG (732.24 KiB) Viewed 2192 times
Any help or pointers would be greatly appreciated!! :)

Cheers,

Kris

User avatar
miax
 
Posts: 157
Joined: Tue Apr 05, 2011 11:41 am

Re: Wave Shield, Mega2560 and DaneElec 2gig SD

Post by miax »

I did some more digging and tried one of these SD cards in the Ethernet shield's SD reader slot. I then installed the latest SDFatLib (sdfatlib2011702) - (http://code.google.com/p/sdfatlib/downloads/list) and used the following sample code (unmodified) from the tutorial page:

Code: Select all

/*
* This sketch uses the microSD card slot on the Arduino Ethernet shield to server
* up files over a very minimal browsing interface
*
* Some code is from Bill Greiman's SdFatLib examples, some is from the Arduino Ethernet
* WebServer example and the rest is from Limor Fried (Adafruit) so its probably under GPL
*
* Tutorial is at http://www.ladyada.net/learn/arduino/ethfiles.html
* Pull requests should go to http://github.com/adafruit/SDWebBrowse
*/

#include <SdFat.h>
#include <SdFatUtil.h>
#include <Ethernet.h>

/************ ETHERNET STUFF ************/
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x3F, 0x48 };
byte ip[] = { 192, 168, 1, 195 };
Server server(80);

/************ SDCARD STUFF ************/
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))

void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

void setup() {
  Serial.begin(9600);
 
  PgmPrint("Free RAM: ");
  Serial.println(FreeRam());
  
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards. use SPI_FULL_SPEED for better performance.
  pinMode(10, OUTPUT); // set the SS pin as an output (necessary!)
  digitalWrite(10, HIGH); // but turn off the W5100 chip!

  if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");
  
  // initialize a FAT volume
  if (!volume.init(&card)) error("vol.init failed!");

  PgmPrint("Volume is FAT");
  Serial.println(volume.fatType(),DEC);
  Serial.println();
  
  if (!root.openRoot(&volume)) error("openRoot failed");

  // list file in root with date and size
  PgmPrintln("Files found in root:");
  root.ls(LS_DATE | LS_SIZE);
  Serial.println();
  
  // Recursive list of all directories
  PgmPrintln("Files found in all dirs:");
  root.ls(LS_R);
  
  Serial.println();
  PgmPrintln("Done");
  
  // Debugging complete, we start the server!
  Ethernet.begin(mac, ip);
  server.begin();
}

void ListFiles(Client client, uint8_t flags) {
  // This code is just copied from SdFile.cpp in the SDFat library
  // and tweaked to print to the client output in html!
  dir_t p;
  
  root.rewind();
  client.println("<ul>");
  while (root.readDir(p) > 0) {
    // done if past last used entry
    if (p.name[0] == DIR_NAME_FREE) break;

    // skip deleted entry and entries for . and ..
    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;

    // only list subdirectories and files
    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;

    // print any indent spaces
    client.print("<li><a href=\"");
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        client.print('.');
      }
      client.print(p.name[i]);
    }
    client.print("\">");
    
    // print file name with possible blank fill
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        client.print('.');
      }
      client.print(p.name[i]);
    }
    
    client.print("</a>");
    
    if (DIR_IS_SUBDIR(&p)) {
      client.print('/');
    }

    // print modify date/time if requested
    if (flags & LS_DATE) {
       root.printFatDate(p.lastWriteDate);
       client.print(' ');
       root.printFatTime(p.lastWriteTime);
    }
    // print size if requested
    if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {
      client.print(' ');
      client.print(p.fileSize);
    }
    client.println("</li>");
  }
  client.println("</ul>");
}

// How big our line buffer should be. 100 is plenty!
#define BUFSIZ 100

void loop()
{
  char clientline[BUFSIZ];
  int index = 0;
  
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    
    // reset the input buffer
    index = 0;
    
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        
        // If it isn't a new line, add the character to the buffer
        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          // are we too big for the buffer? start tossing out data
          if (index >= BUFSIZ)
            index = BUFSIZ -1;
          
          // continue to read more data!
          continue;
        }
        
        // got a \n or \r new line, which means the string is done
        clientline[index] = 0;
        
        // Print it out for debugging
        Serial.println(clientline);
        
        // Look for substring such as a request to get the root file
        if (strstr(clientline, "GET / ") != 0) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          
          // print all the files, use a helper to keep it clean
          client.println("<h2>Files:</h2>");
          ListFiles(client, LS_SIZE);
        } else if (strstr(clientline, "GET /") != 0) {
          // this time no space after the /, so a sub-file!
          char *filename;
          
          filename = clientline + 5; // look after the "GET /" (5 chars)
          // a little trick, look for the " HTTP/1.1" string and
          // turn the first character of the substring into a 0 to clear it out.
          (strstr(clientline, " HTTP"))[0] = 0;
          
          // print the file we want
          Serial.println(filename);

          if (! file.open(&root, filename, O_READ)) {
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<h2>File Not Found!</h2>");
            break;
          }
          
          Serial.println("Opened!");
                    
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/plain");
          client.println();
          
          int16_t c;
          while ((c = file.read()) > 0) {
              // uncomment the serial to debug (slow!)
              //Serial.print((char)c);
              client.print((char)c);
          }
          file.close();
        } else {
          // everything else is a 404
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>File Not Found!</h2>");
        }
        break;
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}
Interestingly enough I get nearly the same result as I got on the wave shield:

Free RAM: 6651
error: card.init failed!
SD error: 1,FF

Is there a correlation here? I'm assuming that I'm just not getting a good format on this Windows 7/64 box (even using the Panasonic formatter) ?

Kris

User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

Re: Wave Shield, Mega2560 and DaneElec 2gig SD

Post by fat16lib »

These are not format problems.

Error code 01 means there is a fundamental hardware problem. WaveHC and SdFat are unable to communicate with the SD.

I ran your Ethernet test on a 2560 Mega, with no mods, using a Kingston MicroSD and it works.
Free RAM: 6651
Volume is FAT16

Files found in root:
TEST.TXT 2011-07-08 04:27:00 0

Files found in all dirs:
TEST.TXT

Done

User avatar
miax
 
Posts: 157
Joined: Tue Apr 05, 2011 11:41 am

Re: Wave Shield, Mega2560 and DaneElec 2gig SD

Post by miax »

fat16lib,

Thanks for the reply and the test! I appreciate it. :)

Hardware problem you say!? I believe this now too - after a night sleep to get the fuzzies out of my eyes, I tried the cards on a new Ethernet shield on my mega and it worked like a charm. :)

However that means I'm screwing up the Wave shield. :( I get the:
Free RAM: 6651
error: card.init failed!
SD error: 1,FF
.. error each time I try either of my wave shields directly on a mega (no other mods or shields. Hopefully support will be able to see where I screwed up...

The only Other thing I noticed (may be just the age of the tutorial), but I noticed in the "SD Card" section of the Wave tutorial it says, "You can use any card that can store 32 MB to 1.0 GB". Of course Adafruit sent me 2 gig cards, which I thought was just a bonus of getting the kit in 2011 when memory prices have come down (still my assumption) - but just wanted to make sure...

Again thanks for testing and confirming that. :) I'm still new to all this!

Cheers,

Kris



Kris

User avatar
fat16lib
 
Posts: 595
Joined: Wed Dec 24, 2008 1:54 pm

Re: Wave Shield, Mega2560 and DaneElec 2gig SD

Post by fat16lib »

Did you run the extra wires required for using the Wave Shield on the Mega?

There are lots of posts in the Forum. Here is an early one:

http://forums.adafruit.com/viewtopic.php?f=31&t=10939

You can search for others.

User avatar
miax
 
Posts: 157
Joined: Tue Apr 05, 2011 11:41 am

Re: Wave Shield, Mega2560 and DaneElec 2gig SD

Post by miax »

fat16lib,

Thank you for pointing that out - I should have looked alot harder before posting all this. :(

My apologies for the entire post - I'll get the hack going AND I'll search alot harder next time.

Cheers and Thanks! :)

Kris

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

Return to “Arduino Shields from Adafruit”