I'm using a Mega 2560 as my board, and I'm trying to play WAV files using the TMRpcm library (found here). Unfortunately, I cannot get the play method to work.
As specified by the library's documentation, I have produced a 2.wav file in 8-bit mono 16 KHz through an iTunes conversion and put in on my SD card.
I'm using the "basic.ino" sketch provided in the library's example folder and have changed the pins accordingly to fit my layout. As recommended by someone who had volume issues with this library, I have speakerPin connected via a 100 Ohm resistor to the gate of a transistor which has the arduino's 5V to source and drain to the positive terminal of my speaker (which is a simple 16 Ohm, 0.5 W speaker I ripped out of a greeting card).
To ensure that I wasn't having hardware issues, I ran toneMelody from Arduino's example projects and it works just fine. I think that means I can safely assume the speaker is good, the wiring is good, and the transistor doesn't mess anything up.
Anyways, below is the modified "basic.ino" sketch I was talking about. The output I get is:
SD card is good
0
Does anyone have any ideas why it might not be working? Thanks!
#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 53 //example uses hardware SS pin 53 on Mega2560
//#define SD_ChipSelectPin 4 //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h> // also need to include this library...
#include <SPI.h>
TMRpcm tmrpcm; // create an object for use in this sketch
void setup(){
tmrpcm.speakerPin = 11; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println("SD fail");
return; // don't do anything more if not
}
Serial.println("SD card is good");
tmrpcm.setVolume(4);
tmrpcm.play("2.wav"); //the sound file "music" will play each time the arduino powers up, or is reset
Serial.println(tmrpcm.isPlaying());
}
void loop(){
if(Serial.available()){
if(Serial.read() == 'p'){ //send the letter p over the serial monitor to start playback
tmrpcm.play("2.wav");
}
}
}