Playing .WAV files

I am trying to play a simple WAV file from a SD.

I have converted the audio file to the correct format (as in other posts) but get this error when compiling.

C:\Users\Documents\Arduino\audio_pgm.ino\audio_pgm.ino\audio_pgm.ino.ino: In function 'void setup()':
C:\Users\Documents\Arduino\audio_pgm.ino\audio_pgm.ino\audio_pgm.ino.ino:18:24: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
 tmrpcm.play("Clint.wav");
                        ^

I cant find a reference to this error?

My test code is;

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

TMRpcm tmrpcm;

void setup()
{
tmrpcm.speakerPin=A6;
Serial.begin(9600);
if(!SD.begin(SD_ChipSelectPin))
{
  Serial.println("SD fail");
  return;
}
tmrpcm.setVolume(6);
tmrpcm.play("Clint.wav");

}

void loop() {
  // put your main code here, to run repeatedly:

}

You’ve posted a warning, not an error.

One way to work around that deficiency in the library:

  char filename[] = "Clint.wav";
  tmrpcm.play(filename);

Thanks John,

I was trying to understand what the warning was telling me and how your solution works.

So your answer creates a character array of the filename and TMRPCM is happy with that?

What is the library limitation?

Thanks again

I've tested the setup of the SD with one of the example programs in the IDE and I can see my WAV file loaded. So I know the wiring etc. is OK

If I monitor A6 with a scope, I can't see an audio file being output.........

A6 is generally an analog input, would be odd to see audio signal as an output there.

Sorry stupid error....

So audio files have to be sent to an output PWM pin but not as an analogWrite, just by using the tmrpcm.play function.

All good now.....

Thanks

kpg:
What is the library limitation?

The author of the library didn't include the 'const' keyword on the argument to .play(). The 'const' is a promise to the compiler that the character pointer won't be used to write data. Since literal constants ("like this") are of type "const char *" you should not be passing them to a function that has not promised not to write on them. It works if the function doesn't ACTUALLY write into the literal.
By using the literal constant to initialize a non-const character array and passing the character array to the function, it doesn't matter if the function writes into the array or not.

CrossRoads:
A6 is generally an analog input, would be odd to see audio signal as an output there.

#define SD_ChipSelectPin 65

The 'basic' example says:

 tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc

It doesn't look like A6 is one of the allowed output pins on a MEGA.

John

Thanks very much for the explanation.

All working now. I have a simple audio amp which it picking up some processor noise but I can fix that later.

This is part of quite a big project and I am a bit new to this but learning fast!

Thanks again

Kev