Audio Trouble Shooting- Mega 2560

Alright guys, so I seem to be struggling a little bit making my project "speak."

I've been building an R2D2 and using a Seeed Micro USB Shield(V4.1). I've been able to run Card Info and get accurate data back about the card; but, when I try to use TMRpcm to access 8bit, 16kHz, .wav files it won't send noise. It makes a noise(a crackle noise) like the pin is activating, but nothing remotely like the R2 noise it's suppose to make. Here is a copy of the last code I thru in:

#include "SD.h"
#define SD_ChipSelectPin 4
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

void setup() 
{
  tmrpcm.speakerPin = 46;
  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin)) 
  {
    Serial.println("SD fail");
    return;
  }

  Serial.println("SD pass");
  //tmrpcm.setVolume(6);
  tmrpcm.play("chat-1 2.wav");
}

void loop() 
{  
}

Thoughts?

Also, I've tried to use the 6 pin micro SD(https://www.amazon.com/gp/product/B01APDJ1TM/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1), but even when I migrate the SS to pin 53 I get nada(my guess- bad board).

It may be a problem with the speaker. I couldn't find information about hooking a speaker to the digital pin, did you?

Hi,
Have you got the filename correct?
Put a sound file on the SD with a simple name like test123

See if it is happy with that.

Tom... :slight_smile:

I copied and pasted the file name.

And just came across another forum post about a similar issue, apparently(in the case of the other person) the problem was due to location the of the OC2A pin(the person was using pin 11, migrated to pin 10 and got it running). So I tried rewriting the code, using pin 10. Now, I'm getting this error:

avrdude: no programmer has been specified on the command line or the config file 
Specify a programmer using the -c option and try again

Fixed:

avrdude: no programmer has been specified on the command line or the config file 
Specify a programmer using the -c option and try again

I migrated the code to pin 10 and changed the .wav name to scream.wav, so the code now reads:

#include "SD.h"
#define SD_ChipSelectPin 4
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

void setup() 
{
  tmrpcm.speakerPin = 10;
  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin)) 
  {
    Serial.println("SD fail");
    return;
  }

  Serial.println("SD pass");
  //tmrpcm.setVolume(6);
  tmrpcm.play("scream.wav");
}

void loop() 
{  
}

Still... No dice.

After running it, with the speaker connected to pin 10, I don't even get a crack or pop...

Thoughts? Suggestions?

See reply #1.

I thought so too. But using the PCM library on an Uno, so that it plays an array of freq., the speaker makes sounds and sounds almost like it's supposed to(sound compression issue, could use a band pass).

The problem with using that approach is that two R2 sounds can use around 80-90% the memory leaving no room for the motor and ultrasonic code, and the library only works on the Uno... Hence why I upgraded to the Mega 2560 and am using the TMRpcm library.

Raw wave data becomes big, the use of a SD card or big external EEPROM is recommended.

That’s just it, all the .wav’s are stored on an SD. Card Info will retrieve the data just fine. But when I try to use the SD and TMRpcm libraries, I get nada.

Attached are two pics of the setup I’m using

If you have checked that the file exists on the SD card, a failure is most probably due to an error or misconfiguration of the TMRpcm library.

Suggestions?

Check out this

AustinBriggs:
After many, many hours of reading and trying various things, I finally figured it out! I solved it by going to the library's header file, pcmConfig.h, and commenting out all the parts in the "GENERAL USER DEFINES" section. This includes:

#define buffSize 128 //must be an even number
#define SD_FULLSPEED
#define HANDLE_TAGS
#define DISABLE_SPEAKER2
#define USE_TIMER2
#define debug

They were already uncommented, so I’m going to “comment” a few back in. Maybe I’ll get lucky.

I commented different #def’s in back in, still no dice.

Currently, I’m getting a constant buzz with #define HANDLE_TAGS commented back in. And using this for my code(I migrated speakerPin to 46):

#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

unsigned long time = 0;

void setup()
{

  tmrpcm.speakerPin = 46; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
  //Complimentary Output or Dual Speakers:
  //pinMode(10,OUTPUT); Pin pairs: 9,10 Mega: 5-2,6-7,11-12,46-45

  Serial.begin(115200);
  pinMode(13, OUTPUT); //LED Connected to analog pin 0
  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

  }
  else
  {
    Serial.println("SD ok");
  }
  tmrpcm.play("scream.wav"); //the sound file "music" will play each time the arduino powers up, or is reset
}



void loop() 
{

  //blink the LED manually to demonstrate music playback is independant of main loop
  if (tmrpcm.isPlaying() && millis() - time > 50 )
  {
    digitalWrite(13, !digitalRead(13));
    time = millis();
  }
  else if (millis() - time > 500)
  {
    digitalWrite(13, !digitalRead(13));
    time = millis();
  }
  tmrpcm.play("scream.wav");
}

Anyone have ANY CLUE with what's going on? Or with what might be the issue?

Hi,

But when I try to use the SD and TMRpcm libraries, I get nada.

Have you checked to see if there is a conflict with timers being used in both libraries in the mega.
Are the libraries Mega compatible?

Tom..... :slight_smile:

I cannot see how the TMRpcm library connects to the SD card. If the SD is not connected as assumed by the library, it's unlikely that it ever will work. At least the library has to know the SS pin of the SD drive.

Hi,
Have you tried the "music" example in the Examples in the IDE , under TMR ?

Tom.... :slight_smile:

DrDiettrich:
I cannot see how the TMRpcm library connects to the SD card.

I'm using the SD.h library too. Should that not be suffice?

TomGeorge:
Hi,
Have you tried the "music" example in the Examples in the IDE , under TMR ?

Tom.... :slight_smile:

That's actually what I used to build the code I'm trying to get to work. I swapped "music" for "scream" and replaced the switch statement.