Go Down

Topic: TMRpcm library unable to play *.wav file - test (Read 356 times) previous topic - next topic

arrchana

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:

Code: [Select]


#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());
     }
  }
}



Please help  :smiley-confuse:  :smiley-confuse:  :smiley-confuse:

pert


DVDdoug

Quote
using -n 8ohm speakers.
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.


Quote
and the buzzer can play sound independently.
What does that mean?   Independent from what?   The sound signal has to come from somewhere.

pieczatka-online

8ohm speakers should normal works in my opinion.

DVDdoug

Quote
8ohm speakers should normal works in my opinion.
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.

Ohm's Law (which defines the relationship between voltage, resistance, and current) is the first thing you learn when you take an electronics class.


arrchana

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

Arduino Uno
You're using an unsupported pin. From the TMRpcm library's documentation:
https://github.com/TMRh20/TMRpcm/wiki#functions
Quote
audio.speakerPin = 11;     set to 5,6,11 or 46 for Mega, 9 for Uno, Nano, etc.
Since you're using an Uno, you must connect the speaker to pin 9.

arrchana

You're using an unsupported pin. From the TMRpcm library's documentation:
https://github.com/TMRh20/TMRpcm/wiki#functionsSince 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:

  tmrpcm.speakerPin = 9;

arrchana

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

Quote
if I call tmrpcm.play("file.wave")
Try and name your file "file.wav" both in the code and your SD card.

arrchana

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?

Grumpy_Mike

You said:-
Quote
if I call tmrpcm.play("file.wave")
the file should have a wav extension not a wave extension.

The other things people get wrong is the wav format. Audacity can cope with more .wav file types than the tmrpcm can.

pert

What do you mean, in my code I did specify pin 9 to be used for the speaker:
You're right. Somehow I read it as 6 in your code. Very strange. I apologize for any confusion.

Go Up