undefined reference to `TMRpcm::play(char*)'

Hello. I am building a project for my uncles Christmas present and I need it to play a sound and light up when either of two button are pressed. I am use this tutorial to set up my board

Here's My error

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Nano w/ ATmega328"
WavSW_ino.cpp.o: In function loop': C:\Program Files (x86)\Arduino/WavSW_ino.ino:28: undefined reference to TMRpcm::play(char*)'
C:\Program Files (x86)\Arduino/WavSW_ino.ino:36: undefined reference to TMRpcm::play(char*)' WavSW_ino.cpp.o: In function setup':
C:\Program Files (x86)\Arduino/WavSW_ino.ino:22: undefined reference to TMRpcm::volume(char)' C:\Program Files (x86)\Arduino/WavSW_ino.ino:23: undefined reference to TMRpcm::play(char*)'

So my code is

 #include <SD.h>                      // need to include the SD library
 #define SD_ChipSelectPin 4  //using digital pin 4 on arduino nano 328
 #include <C:\Users\L\Documents\Arduino\libraries\TMRpcm-master\TMRpcm/TMRpcm.h>           //  also need to include this library...
 
 TMRpcm tmrpcm;   // create an object for use in this sketch
 int inputPin1 = 14;    
 int inputPin2 = 15;

 
void setup(){
 pinMode(inputPin1, INPUT);  
 pinMode(inputPin2, INPUT); 
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 
  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(){  
   if (digitalRead(inputPin1) == LOW) {     
       tmrpcm.play("6.wav");  
       digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(8, HIGH);  // turn the LED on (HIGH is the voltage level)
       delay(1000);  // wait for a second
       digitalWrite(7, LOW);
       digitalWrite(8, LOW);
  }
  else if (digitalRead(inputPin2) == LOW)  {      
       tmrpcm.play("6.wav");  
       digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(8, HIGH);  // turn the LED on (HIGH is the voltage level)
       delay(1000);  // wait for a second
       digitalWrite(7, LOW);
       digitalWrite(8, LOW);   
  }  
}

so basically depending on the button pressed the it will light up and play 1 of 2 sound files. I just can't figure out how to solve this error. I thankful for your help.

Hello and welcome,

Try renaming the library folder from "TMRpcm-master" to just "TMRpcm", and then change your include line to

#include <TMRpcm.h>

Thanks for the welcome, after doing that I get this error

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Nano w/ ATmega328"
WavSW_ino.cpp.o: In function loop': C:\Program Files (x86)\Arduino/WavSW_ino.ino:28: undefined reference to TMRpcm::play(char*)'
C:\Program Files (x86)\Arduino/WavSW_ino.ino:36: undefined reference to TMRpcm::play(char*)' WavSW_ino.cpp.o: In function setup':
C:\Program Files (x86)\Arduino/WavSW_ino.ino:22: undefined reference to TMRpcm::volume(char)' C:\Program Files (x86)\Arduino/WavSW_ino.ino:23: undefined reference to TMRpcm::play(char*)'

 #include <SD.h>                      // need to include the SD library
 #define SD_ChipSelectPin 4  //using digital pin 4 on arduino nano 328
 #include <C:\Users\L\Documents\Arduino\libraries\TMRpcm\TMRpcm\TMRpcm.h>           //  also need to include this library...
 
 TMRpcm tmrpcm;   // create an object for use in this sketch
 int inputPin1 = 14;    
 int inputPin2 = 15;

 
void setup(){
 pinMode(inputPin1, INPUT);  
 pinMode(inputPin2, INPUT); 
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 
  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(){  
   if (digitalRead(inputPin1) == LOW) {     
       tmrpcm.play("6.wav");  
       digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(8, HIGH);  // turn the LED on (HIGH is the voltage level)
       delay(1000);  // wait for a second
       digitalWrite(7, LOW);
       digitalWrite(8, LOW);
  }
  else if (digitalRead(inputPin2) == LOW)  {      
       tmrpcm.play("6.wav");  
       digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(8, HIGH);  // turn the LED on (HIGH is the voltage level)
       delay(1000);  // wait for a second
       digitalWrite(7, LOW);
       digitalWrite(8, LOW);   
  }  
}

Just in case, I also try this

 #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 inputPin1 = 14;    
 int inputPin2 = 15;

 
void setup(){
 pinMode(inputPin1, INPUT);  
 pinMode(inputPin2, INPUT); 
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 
  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(){  
   if (digitalRead(inputPin1) == LOW) {     
       tmrpcm.play("6.wav");  
       digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(8, HIGH);  // turn the LED on (HIGH is the voltage level)
       delay(1000);  // wait for a second
       digitalWrite(7, LOW);
       digitalWrite(8, LOW);
  }
  else if (digitalRead(inputPin2) == LOW)  {      
       tmrpcm.play("6.wav");  
       digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)
       digitalWrite(8, HIGH);  // turn the LED on (HIGH is the voltage level)
       delay(1000);  // wait for a second
       digitalWrite(7, LOW);
       digitalWrite(8, LOW);   
  }  
}

and got this error

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Nano w/ ATmega328"
WavSW_ino:6: error: 'TMRpcm' does not name a type
WavSW_ino.ino: In function 'void setup()':
WavSW_ino:17: error: 'tmrpcm' was not declared in this scope
WavSW_ino.ino: In function 'void loop()':
WavSW_ino:28: error: 'tmrpcm' was not declared in this scope
WavSW_ino:36: error: 'tmrpcm' was not declared in this scope

so it does look like that it sees the TMRpcm.h when I do it the other way but I am not sure on the above error.

Here's TMRpcom.h

/*Library by TMRh20 2012-2014

Contributors:

  ftp27 (GitHub) - setVolume(); function and code
  muessigb (GitHub) - metatata (ID3) support

*/

#ifndef TMRpcm_h   // if x.h hasn't been included yet...
#define TMRpcm_h   //   #define this so the compiler knows it has been included

#include <Arduino.h>
#include <pcmConfig.h>
#include <pcmRF.h>
#if !defined (SDFAT)
	#include <SD.h>
#else
	#include <SdFat.h>
#endif

#if defined (ENABLE_RF)
	class RF24;
#endif

class TMRpcm
{
 public:
 	//TMRpcm();
 	//*** General Playback Functions and Vars ***
	void play(char* filename);
	void stopPlayback();
	void volume(char vol);
	void setVolume(char vol);
	void disable();
	void pause();
	void quality(boolean q);
	void loop(boolean set);
	byte speakerPin;
	boolean isPlaying();
    uint8_t CSPin;

	//*** Public vars used by RF library also ***
	boolean wavInfo(char* filename);
	boolean rfPlaying;
	unsigned int SAMPLE_RATE;

	//*** Advanced usage Vars ***
	byte listInfo(char* filename, char *tagData, byte infoNum);
	byte id3Info(char* filename, char *tagData, byte infoNum);
	byte getInfo(char* filename, char* tagData, byte infoNum);


	#if !defined (ENABLE_MULTI)//Normal Mode
		void play(char* filename, unsigned long seekPoint);

	//*** MULTI MODE **
	#else
		void quality(boolean q, boolean q2);
		void play(char* filename, boolean which);
		void play(char* filename, unsigned long seekPoint, boolean which);
		boolean isPlaying(boolean which);
		void stopPlayback(boolean which);
		void volume(char upDown,boolean which);
		void setVolume(char vol, boolean which);
		void loop(boolean set, boolean which);
	#endif
	#if defined (MODE2)
			byte speakerPin2;
	#endif

	//*** Recording WAV files ***
	void createWavTemplate(char* filename,unsigned int sampleRate);
	void finalizeWavTemplate(char* filename);
	#if defined (ENABLE_RECORDING)
		void startRecording(char* fileName, unsigned int SAMPLE_RATE, byte pin);
		void startRecording(char *fileName, unsigned int SAMPLE_RATE, byte pin, byte passThrough);
		void stopRecording(char *fileName);
	#endif

 private:

 	void setPin();
	void timerSt();
	unsigned long fPosition();
	unsigned int resolution;
	byte lastSpeakPin;
	byte metaInfo(boolean infoType, char* filename, char* tagData, byte whichInfo);
	boolean seek(unsigned long pos);
	boolean ifOpen();

	#if !defined (SDFAT)
		boolean searchMainTags(File xFile, char *datStr);
	#else
		unsigned long searchMainTags(SdFile xFile, char *datStr);
	#endif

	#if defined (ENABLE_MULTI)
		void ramp(boolean wBuff);
	#endif

	#if defined (MODE2)
		void setPins();
	#endif
};

#endif

and pcmConfig

/*
This library was intended to be a simple and user friendly wav audio player using standard
Arduino libraries, playing bare-bones standard format WAV files.

Many of the extra features have been added due to user request, and are enabled
optionally only to preserve the out of the box simplicity and performance initially
intended.

Code/Updates: https://github.com/TMRh20/TMRpcm
Wiki: https://github.com/TMRh20/TMRpcm/wiki
Blog: https://tmrh20.blogspot.com/

*/


#ifndef pcmConfig_h   // if x.h hasn't been included yet...
#define pcmConfig_h   //   #define this so the compiler knows it has been included

#include <Arduino.h>



/****************** GENERAL USER DEFINES *********************************
 See https://github.com/TMRh20/TMRpcm/wiki for info on usage

   Override the default size of the buffers (MAX 254). There are 2 buffers, so memory usage will be double this number
   Defaults to 64bytes for Uno etc. 254 for Mega etc. note: In multi mode there are 4 buffers*/
//#define buffSize 128  //must be an even number

  /* Uncomment to run the SD card at full speed (half speed is default for standard SD lib)*/
#define SD_FULLSPEED

  /* HANDLE_TAGS - This options allows proper playback of WAV files with embedded metadata*/
#define HANDLE_TAGS

  /*Ethernet shield support etc. The library outputs on both timer pins, 9 and 10 on Uno by default. Uncommenting this
    will disable output on the 2nd timer pin and should allow it to function with shields etc that use Uno pin 10 (TIMER1 COMPB).*/
#define DISABLE_SPEAKER2

  /* Use 8-bit TIMER2 - If using an UNO, Nano, etc and need TIMER1 for other things*/
#define USE_TIMER2

#define debug
/****************** ADVANCED USER DEFINES ********************************
   See https://github.com/TMRh20/TMRpcm/wiki for info on usage

   /* Use the SDFAT library from http://code.google.com/p/sdfatlib/            */
//#define SDFAT

   /* MULTI Track mode currently allows playback of 2 tracks at once          */
//#define ENABLE_MULTI  //Using separate pins on a single 16-bit timer

   /* Enables 16-bit samples, which can be used for stereo playback, or to produce a
	   pseudo 16-bit output.                                                   */
//#define STEREO_OR_16BIT

   /* In Normal single track mode, MODE2 will modify the behavior of STEREO or 16BIT output
        With MODE2 off, stereo tracks will be played using 2 pins, for 2 speakers in non-complimentary mode (pin to ground)
	    With MODE2 on, stereo tracks will be played using 4 pins, for 2 speakers in complimentary mode
	  In MULTI dual track mode, MODE2 will use a second timer for the second track.
	    With MODE2 off, each track will use a separate pin, but the same timer
	                                                                           */
//#define MODE2  //Using separate 16-bit timers with up to 4 pins (Arduino Mega etc only)

   /* The library uses two different ramping methods to prevent popping sounds
      when PWM is enabled or disabled. This option is autodetected unless defined here*/
//#define rampMega

   /* Initial implementation for recording of WAV files to SD card via a microphone or input connected to an analog pin
   SdFat library is recommended
   Requires a class 4 card minimum, buffSize may need to be increased to 254 if audio is skipping etc.
   Depending on the card, can take a few seconds for recording to start
   																									*/
//#define ENABLE_RECORDING
	// Amount of space to pre-allocate for recording
//	#define BLOCK_COUNT 10000UL  // 10000 = 500MB   2000 = 100MB

//*********************** Radio (NRF24L01+) Streaming *********************

   /* Comment or Uncomment to en/disable RF streaming of wav files. Make sure
to Comment if not using radio                                                  */

//#define ENABLE_RF

  /* Uncomment this line to disable all standard features except RF playback.
     This will minimize resource usage if not playing or recording files locally */
//#define RF_ONLY

//*************************************************************************

#endif

You installed the library wrong, the path to TMRpcm.h and other files of that library, should be:

Documents/Arduino/libraries/TMRpcm

So that the folder structure look like this:

Documents/Arduino/libraries/TMRpcm/keywords.txt 
Documents/Arduino/libraries/TMRpcm/pcmConfig.h 
Documents/Arduino/libraries/TMRpcm/pcmRF.cpp 
Documents/Arduino/libraries/TMRpcm/pcmRF.h 
Documents/Arduino/libraries/TMRpcm/README 
Documents/Arduino/libraries/TMRpcm/TMRpcm.cpp 
Documents/Arduino/libraries/TMRpcm/TMRpcm.h 
Documents/Arduino/libraries/TMRpcm/examples/basic 
Documents/Arduino/libraries/TMRpcm/examples/music 
Documents/Arduino/libraries/TMRpcm/examples/progmem 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures 
Documents/Arduino/libraries/TMRpcm/examples/basic/basic.ino 
Documents/Arduino/libraries/TMRpcm/examples/music/music.ino 
Documents/Arduino/libraries/TMRpcm/examples/progmem/progmem.ino 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/MultiTrack_2Pins 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/MultiTrack_4Pins 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/Recording 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/sdfat 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/Stereo_2Pins 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/streamingExamples 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/wavGeneration 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/MultiTrack_2Pins/MultiTrack_2Pins.ino 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/MultiTrack_4Pins/MultiTrack_4Pins.ino 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/Recording/Recording.ino 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/sdfat/sdfat.ino 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/Stereo_2Pins/Stereo_2Pins.ino 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/streamingExamples/musicStreamerComplex 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/streamingExamples/musicStreamerSimple 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/streamingExamples/README.txt 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/streamingExamples/musicStreamerComplex/musicStreamerComplex.ino 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/streamingExamples/musicStreamerComplex/printf.h 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/streamingExamples/musicStreamerSimple/musicStreamerSimple.ino 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/streamingExamples/musicStreamerSimple/printf.h 
Documents/Arduino/libraries/TMRpcm/examples/xtraFeatures/wavGeneration/wavGeneration.ino 
Documents/Arduino/libraries/TMRpcm/RF_AddOn/README.txt

Then you include it like this:

#include <TMRpcm.h>

Yahoo it seems to be working, if I have anymore troubles I post them by midnight. Thanks again, also I did the auto install of the library I'll do it manually next time.

Okay so, I think the ardunio isn't reading the micro sd card reader. :frowning: the card reader has pins 3v3 cs mosi clk miso gnd 1, 2, 3, 4, 5, 6

the sd card reader has pins
GND 3v3 5V CS MOSI SCK MISO GND, 1,2 3, 4, 5, 6, 7, 1

So
I connected my 3v3 to 3v3
I connected my CS to their CS at D4
I connected my MOSI to their MOSI on D12 my 3 their 5
I connected my CLK to D13, but they connected SCK to D13
I connected my MISO and their MOSI on D11 so my
I connected GND to GND

the only difference is that I have a clk and they have a SCK is this proper does my clk have to be on a different pin, if so does it need to be changed in the program?

Hi, hope you have got this sorted now but if not...

Make sure your SD card is formatted to FAT16 or FAT32.

If you are not using a shield..
you'll need a buffer to convert the outputs from the arduino from 5v to 3.3v (sn74ahc125n works for me)

I've attached a quick sketch for the wiring (note it shows pin 10 to CS but most code uses pin 4 either works but pin 4 is probably better, its an old sketch!)

Buy a SD card holder, it will make things a lot more reliable.

Just stuff I've found muddling through.

20150131_230853[1].jpg