sd card failed to initialize, tmrpcm not playing. I'm out of ideas. Anyone?

I'm looking for anyone with expertise in getting any of these SD card music playing libraries to work. I have this beautiful custom shield all built up for my freetronics usb droid r3 but all my tests and google results have not been able to get a music output. Many people on instructables and youtube have apparently got this working with a simple understanding and a low amount of hardware + software. That's pretty frustrating since i'm sure i've followed all instructions and manuals available.

First, I will start with my knowledge of SD card interfacing. An SD card must be formatted with the official formatting software in place of operating system formatters. The card must not be formatted more than, say, 5 times quick format and I have experienced the destruction of a card due to. My second card was quick formatted to FAT32 I have heard that cards below 2GB must be FAT16 but design but it's just something to tick off. The files on board are 8bit, 8-32Khz sample rate, mono wav files with the 8.3 naming convention as per the limits of the tmrpcm library.

I did find that the output for SD.begin() was false, indicating that the card could not be initialized. It's my only lead since i've tested all my sensor logic with different outputs such as writing to serial or just a plain analogWrite(127). That's all working so everything points to either the tmrpcm library or the SD card. Google had a lot of helpless souls with uninitialized SD cards but none of the solutions there seem to help. Where to from here?

#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>
#include <SD.h>
#include <SPI.h>            //due to a problem with the SD library, research suggest this must be included to access that library.
#define SDChipSelectPin 10  //we use this pin as a sensor to detect if sd card is present.
TMRpcm tmrpcm;              //creates an object pointing at the TMRpcm library for use in this sketch.
  
void setup()
{
  Serial.begin(9600); // allows communication with the computer at 9600 bits/s.
  
  if (!SD.begin(SDChipSelectPin)) 
  {
    Serial.println("Can't detect sd card.");  //check the sd card is working.
    return;
  }
  
  else 
  {
    Serial.println("SD card detected.");
  }
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);         //chip select pin for spi must be a constant output.
  digitalWrite(10, HIGH);      //this line is just a google solution; it doesnt seem to change much.
  
  if (!SD.begin()) {
    Serial.println("Failed!");
    while (true); //end program at the error.
  }
  Serial.println("SD card initialized.");

  if (!SD.open("sound1.wav"))
  {
    Serial.println("could not open file.");
    while (true);  //end program at the error. 
  }
  pinMode(14,INPUT);     //pin A0.
  pinMode(15,INPUT);     //pin A1.
  pinMode(16,INPUT);     //pin A2.
  pinMode(17,INPUT);     //pin A3.
  pinMode(18,INPUT);     //pin A4.
  pinMode(19,INPUT);     //pin A5.
  pinMode(6,OUTPUT);    //PWM pin D6. //pulse width modulated output with constant voltage of vcc.
  tmrpcm.speakerPin = 6;
  tmrpcm.volume(1);
  tmrpcm.setVolume(4); 
}

void loop() 
{
  float pinA0 = analogRead(14) * (5.0 / 1023.0); //this equation converts the analogue read value (0-255) into a float voltage value similar to input.
  float pinA1 = analogRead(15) * (5.0 / 1023.0);
  float pinA2 = analogRead(16) * (5.0 / 1023.0);
  float pinA3 = analogRead(17) * (5.0 / 1023.0);
  float pinA4 = analogRead(18) * (5.0 / 1023.0);
  float pinA5 = analogRead(19) * (5.0 / 1023.0);

  if (pinA0 > 3)
  {
    Serial.println("Button 1 pressed.");
    tmrpcm.stopPlayback();
    tmrpcm.play("sound1.wav");   //the maximum values played are 32KHz sampling, mono 8 bit unsigned WAV.
    delay(200); 
  }

  if (pinA1 > 3)
  {
    Serial.println("Button 2 pressed.");
    tmrpcm.stopPlayback();
    tmrpcm.play("sound2.wav");  
    delay(200); 
  } 
    
  if (pinA2 > 3)
  {
    Serial.println("Button 3 pressed.");
    tmrpcm.stopPlayback();
    tmrpcm.play("sound3.wav");  
    delay(200); 
  }  
  
  if (pinA3 > 3)
  {
    Serial.println("Button 4 pressed.");
    tmrpcm.stopPlayback();
    tmrpcm.play("sound4.wav");  
    delay(200); 
  }
    
  if (pinA4 > 3)
  {
    Serial.println("Button 5 pressed.");
    tmrpcm.stopPlayback();
    tmrpcm.play("sound5.wav");  
    delay(200);  
  }
    
  if (pinA5 > 3)
  {
    Serial.println("Button 6 pressed.");
    tmrpcm.stopPlayback();
    tmrpcm.play("sound6.wav");  
    delay(200); 
  } 
  
  Serial.print(pinA0);
  Serial.print(" ");
  Serial.print(pinA1);
  Serial.print(" ");
  Serial.print(pinA2);
  Serial.print(" ");
  Serial.print(pinA3);
  Serial.print(" ");
  Serial.print(pinA4);
  Serial.print(" ");
  Serial.println(pinA5); 
  
}

I'd check the SD card interface first. Remove all other libraries (#include...) and calls.

Check whether the SPI libraries are required for the SD card initialization. If not, drop them from your sketch. Only add these again when reading the SD card fails (later).

If this doesn't work, something is wrong with the SD card, board or wiring.

Will it help to move the SD card CS to a different pin?

Then add the other libraries again, but do not use them. This could reveal resource conflicts in the libraries.

Then add the TMRpcm object, check.
Then add its setup code and check.

DrDiettrich:
snip

this is a good reply ill tick all these ideas off by tomorrow.

the sd hardware is built into the board of the freetronics usb droid r3 and the mob there claim 100% compatibility with the uno. i assumed the sd library would already have all its pins aligned for the uno but since the uno would use an external sd shield, the library must be sending data straight down the digital headers. they have a great forum with employees to reply to trivial questions so im there as well.

Instead of SD.h, I'd suggest SDFat.h.

SD.begin is now indicating the card is working proper thanks to a switch to SDFAT. however, the tmrpcm library still wont output music. It does output a pop every time the play function is called and my speaker set up has already passed tests.

I've had a hunch since I heard the uno has only two timers. I found something interesting in the TMRpcm.cpp file in the tmrpcm library. On line 231 it mentions in a comment that if speaker pin set to 6, which is true in my case, program will use timer 4... which doesnt exist. I changed it to use timer 1 and now every time I press a play button the d12 on board led starts flickering, for about a minute, then stops. When I revert line 231 back to default, it will no longer flash. I'm close enough to taste success! :slight_smile: but still stuck. :o

EDIT the led lit time is exactly the time taken to play the file!! but no output. ill double check my speaker pin and output scheme tomorrow since it seems the music is playing.

if (!SD.begin(SDChipSelectPin)) 
  {
    Serial.println("Can't detect sd card.");  //check the sd card is working.
    while (true);
  }
  Serial.println("SD card detected.");
  Serial.print("Initializing SD card...");
  
  if (!SD.begin()) {
    Serial.println(" Failed!");
    while (true); //end program at the error.
  }
  Serial.println(" SD card initialized.");
  Serial.print("reading file...");
  
  if (!SD.open("sound1.wav"))
  {
    Serial.println(" could not open file.");
    while (true);  //end program at the error. 
  }
  Serial.println(" file opened; all tests succeeded!");

SD card detected.
Initializing SD card... SD card initialized.
Reading file... File opened; All tests succeeded!

thanks for the informative responses you've both helped me to get sd card "working" unfortunately there is an urgency of time with these school projects so ill open a new topic for the tmrpcm.play(). it looks like that function actually plays but nothing comes out. i made sure timer 2 was not contested and changed that in the config.h file. i think ive tested all the easy absent minded problems and its probably something to do with the logic of the library and outside my expertise.