Hi
I am a complete newbie at this so please forgive my ignorance. I have some programming knowledge, though not in arduino, and virtually no electronics knowledge. However, a friend of mine has asked me to help with the programming side of setting up an arduino (it's actually a clone I believe) to operate the sounds on his model railway. He has good electronics knowledge.
The problem is, we are completely unable to get sounds out of the board. I have used sketch to upload the code to the board, which appears upload ok. When I click to upload the board flashes and I get no error messages. However I do get a series of warnings. When we press the switches on the circuit which are supposed to play the sounds nothing happens. Assuming the electronics on the breadboard are all wired up correctly, is there anything I am doing with the software that would cause this not to work. The breadboard is wired-up up with the Arduino and an SD card storing the sounds in WAV format. We have tried different formats for the WAV sounds, but to no avail.
Here is the code I am using:
#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 4 //using digital pin 4 on arduino nano 328
#include <TMRpcm.h> // also need to include this library...TMRpcm tmrpcm; // create an object for use in this sketch
int SW1;
int SW2;
int SW3;
int SW4;
void setup(){
pinMode(14,INPUT); //Define A0 as digital input.
pinMode(15,INPUT); //Define A1 as digital input.
pinMode(16,INPUT); //Define A2 as digital input.
pinMode(17,INPUT); //Define A3 as digital input.tmrpcm.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
return; // don't do anything more if not
}
tmrpcm.volume(1);
tmrpcm.play("1.wav"); //the sound file "1" will play each time the arduino powers up, or is reset
}void loop(){
SW1=digitalRead(14);
SW2=digitalRead(15);
SW3=digitalRead(16);
SW4=digitalRead(17);if (SW1 == LOW) { //if SW1 pressed then play file "6.wav"
tmrpcm.play("6.wav");
} else if(SW2 == LOW){ //if SW2 pressed then play file "4.wav"
tmrpcm.play("4.wav");
} else if(SW3 == LOW){ //if SW3 pressed then play file "5.wav"
tmrpcm.play("5.wav");
} else if(SW4 == LOW){ //if SW4 pressed then play file "3.wav"
tmrpcm.play("3.wav");
}}
And these are the warnings when I upload the code:
C:\Users\davidandhazel\Documents\Arduino\Sample\WavSW_ino\WavSW_ino.ino: In function 'void setup()':
C:\Users\davidandhazel\Documents\Arduino\Sample\WavSW_ino\WavSW_ino.ino:22:21: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
tmrpcm.play("1.wav"); //the sound file "1" will play each time the arduino powers up, or is reset
^
C:\Users\davidandhazel\Documents\Arduino\Sample\WavSW_ino\WavSW_ino.ino: In function 'void loop()':
C:\Users\davidandhazel\Documents\Arduino\Sample\WavSW_ino\WavSW_ino.ino:32:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
tmrpcm.play("6.wav");
^
C:\Users\davidandhazel\Documents\Arduino\Sample\WavSW_ino\WavSW_ino.ino:34:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
tmrpcm.play("4.wav");
^
C:\Users\davidandhazel\Documents\Arduino\Sample\WavSW_ino\WavSW_ino.ino:36:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
tmrpcm.play("5.wav");
^
C:\Users\davidandhazel\Documents\Arduino\Sample\WavSW_ino\WavSW_ino.ino:38:26: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
tmrpcm.play("3.wav");
^
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp: In member function 'byte TMRpcm::metaInfo(boolean, char*, char*, byte)':
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1381:18: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* datStr = "LIST";
^
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1382:28: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
if(infoType == 1){datStr = "ID3 "; datStr[3] = 3;}
^
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1410:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
char* tagNames[] = {"INAM","IART","IPRD"};
^
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1410:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1410:42: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1430:16: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
tagNames[0] = "TPE1"; tagNames[1] ="TIT2"; tagNames[2] ="TALB";
^
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1430:38: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
tagNames[0] = "TPE1"; tagNames[1] ="TIT2"; tagNames[2] ="TALB";
^
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1430:59: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
tagNames[0] = "TPE1"; tagNames[1] ="TIT2"; tagNames[2] ="TALB";
^
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp: In member function 'void TMRpcm::finalizeWavTemplate(char*)':
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1568:65: warning: narrowing conversion of '(fSize >> 16)' from 'long unsigned int' to 'byte {aka unsigned char}' inside { } [-Wnarrowing]
seek(4); byte data[4] = {lowByte(fSize),highByte(fSize), fSize >> 16,fSize >> 24};
^
C:\Users\davidandhazel\Documents\Arduino\libraries\TMRpcm-master\TMRpcm.cpp:1568:77: warning: narrowing conversion of '(fSize >> 24)' from 'long unsigned int' to 'byte {aka unsigned char}' inside { } [-Wnarrowing]
seek(4); byte data[4] = {lowByte(fSize),highByte(fSize), fSize >> 16,fSize >> 24};
^
Sketch uses 14,554 bytes (47%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,051 bytes (51%) of dynamic memory, leaving 997 bytes for local variables. Maximum is 2,048 bytes.
So I suppose my questions are:
- Is there anything obviously wrong in the code (assuming filenames are correct etc)?
- Has the code been uploaded to the Arduino? Is there a way to tell?
- Is there anything else we should check or any other ideas for moving forwards?
Thanks so much for your help.