All I want to do is play a song on my SD card using an SD card reader using an 8ohm speakers. I'm confident the circuit works as I tested the Arduino's ability to read files off the side card, and the buzzer can play sound independently.
I'm using TMRpcm library to play a *.wav file off of the SD card using the play() method however, after calling tmrpcm.play("file.wave"), I call tmrpcm.isPlaying() immediately and alway get a 0. Why is this? Also, no sound is made.
I've saved the *.wave file with an 8 bit resolution, 8kHz sampling rate, and audio channel set to mono (as opposed to stereo) so, I don't think the issue is with the way the file was save. Nor do I think the issue is the circuit, as mentioned, independently, parts work.
Here's my code:
#include "SD.h"
#define SD_ChipSelectPin 10
#include "TMRpcm.h"
#include "SPI.h"
TMRpcm tmrpcm;
void setup(){
tmrpcm.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
Serial.println("SD is good");
}
void loop(){
if(Serial.available()){
if(Serial.read() == 'p'){ //send the letter p over the serial monitor to start playback
audio.quality(1)
tmrpcm.setVolume(4);
tmrpcm.play("MOTH"); // note there are 4 plays here because I'm not sure how .play() is expecting the file name - I've each and none of them make a difference. The actual file is named "moth.wav"
tmrpcm.play("MOTH.WAV");
tmrpcm.play("moth");
tmrpcm.play("moth.wav");
Serial.println(tmrpcm.isPlaying());
}
}
}
This is probably unrelated to your problem but I hope you didn't directly connect 8-Ohm speakers to the Arduino. The "absolute maximum" current rating of 40mA (at 5V) works-out to a minimum load resistance of 125 Ohms. With excess current you can get "unpredictable" performance, or even a fried Arduino.
If the speakers are directly-connected try running the program with no speakers to see if you get the same "error".
In any case, you'll need to add an amplifier for regular 4 or 8-Ohm speakers or you can use "powered" computer speakers, etc. Or for testing you can put a resistor (120-Ohms or more) in series with the speaker but that will greatly reduce the volume.
and the buzzer can play sound independently.
What does that mean? Independent from what? The sound signal has to come from somewhere.
It may "work" and you are free to do whatever you want but it's bad practice to ignore the specs.
If you post a design like that on the Internet you will be ridiculed and if you were a design engineer you wouldn't have your job very long.
[u]Ohm's Law[/u] (which defines the relationship between voltage, resistance, and current) is the first thing you learn when you take an electronics class.
DVDdoug: This is probably unrelated to your problem but I hope you didn't directly connect 8-Ohm speakers to the Arduino. The "absolute maximum" current rating of 40mA (at 5V) works-out to a minimum load resistance of 125 Ohms. With excess current you can get "unpredictable" performance, or even a fried Arduino.
If the speakers are directly-connected try running the program with no speakers to see if you get the same "error".
In any case, you'll need to add an amplifier for regular 4 or 8-Ohm speakers or you can use "powered" computer speakers, etc. Or for testing you can put a resistor (120-Ohms or more) in series with the speaker but that will greatly reduce the volume.
What does that mean? Independent from what? The sound signal has to come from somewhere.
No, I didn't hook the 8ohm speaker directly in to the Arduino. In the setup I'm using a transistor and resistor. I used Example Arduino buzzer code with the 8ohm speaker setup in place and it makes noise.
I honestly don't think the issue is the circuit - I'm pretty sure the issue has to do with the code and the tmrpcm.play() method
pert:
You're using an unsupported pin. From the TMRpcm library's documentation: Home · TMRh20/TMRpcm Wiki · GitHub you're using an Uno, you must connect the speaker to pin 9.
What do you mean, in my code I did specify pin 9 to be used for the speaker:
DVDdoug:
If the speakers are directly-connected try running the program with no speakers to see if you get the same "error".
I already tried that, regardless of whether the speaker is plugged in or not, if I call tmrpcm.play("file.wave") followed by tmrpcm.isPlaying(), isPlaying always outputs a 0........ with and without the speaker plugged in correctly
I have a feeling I'm missing something on the software/library/code side - unless somehow the library is able to tell that my circuit isn't hooked up properly (even though the individuals components work on their own)... resulting in tmrpcm.isPlaying() to output 0, even though tmrpcm.play() was called
Grumpy_Mike:
Try and name your file "file.wav" both in the code and your SD card.
On my SD card the file is named "moth.wav" and in the code I refer to it as shown above - why do you think changing the file name is both locations to "file.wav" is going to help?