Hi
I have a project that passes data from a Mega 2560 to an Uno using wire.h that is hosting a MP3 Music Maker shield. The data that is passed and turned into a string is simply the name of a track that I wish to play from the tracks one the SD card.
I have assigned a String variable called playtrack which hold the name of the track to play. i.e. beatles1.mp3 This example track is on the SD card.
If I use the command ;
musicPlayer.playFullFile("beatles1.mp3");
the track plays fine.
If I assign the the value to the string variable using playtrack = beatles1.mp3 and try and use,
musicPlayer.playFullFile(playtrack);
I get a compile error: Music_Shield1:78: error: no matching function for call to 'Adafruit_VS1053_FilePlayer::playFullFile(String&)'
Seems I cannot use a variable to name the track I want to play only the full track name. I did also try manipulating the playtrack string to ensure it output was enclosed in quotes i.e "beatles1.mp3" but again got the same error.
I have done Serial.print(playtrack) ; and the output shows beatles1.mp3 or "beatles1.mp3" (with the quotes added) so that appears that the variable is holding the track name correctly.
I am using IDE 1.8.5
This the the last bit of a large project I have been working on and I cannot use the Shield on the Mega as most of the I/O pins are used.
I would be very grateful if anybody could offer me some advice on this as I seems to be going round in circles at the moment. I think the problems could lie with the SD library not able to accept a string variable instead of a filename.
I have posted my code at the bottom of this post and the full error message below that.
Thank you in advance
Chazza
// include SPI, MP3 and SD libraries
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
String readString;
String playtrack = "";
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
#define CARDCS 4 // Card chip select pin
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600);
Serial.println("Adafruit VS1053 Simple Test");
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
while (1);
}
Serial.println(F("VS1053 found"));
if (!SD.begin(CARDCS)) {
Serial.println(F("SD failed, or not present"));
while (1); // don't do anything more
}
// Set volume for left, right channels. lower numbers == louder volume!
//30 is a good value for active speakers
musicPlayer.setVolume(40, 40);
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
}
void loop() {
if (readString.length() >11) {
Serial.println(readString);
playtrack = readString;
Serial.println(playtrack); // this prints out beatles1.mp3
// musicPlayer.playFullFile("beatles1.mp3"); // this plays correctly
// musicPlayer.playFullFile(playtrack); // this causes an error
readString="";
}
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany){
while (0 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
readString += c;
}
}
Full Error message
Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"
D:\Music_Shield1.ino: In function 'void loop()':
Music_Shield1:53: error: no matching function for call to 'Adafruit_VS1053_FilePlayer::playFullFile(String&)'
musicPlayer.playFullFile(playtrack); // this causes an error
^
D:\Music_Shield1\Music_Shield1.ino:53:35: note: candidate is:
In file included from D:\Charin\Escape Rooms\Hell Door\Music_Shield1\Music_Shield1.ino:5:0:
C:\Program Files (x86)\Arduino\libraries\Adafruit_VS1053_Library-master/Adafruit_VS1053.h:176:11: note: boolean Adafruit_VS1053_FilePlayer::playFullFile(const char*)
boolean playFullFile(const char *trackname);
^
C:\Program Files (x86)\Arduino\libraries\Adafruit_VS1053_Library-master/Adafruit_VS1053.h:176:11: note: no known conversion for argument 1 from 'String' to 'const char*'
Multiple libraries were found for "SD.h"
Used: C:\Program Files (x86)\Arduino\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SDCopy
exit status 1
no matching function for call to 'Adafruit_VS1053_FilePlayer::playFullFile(String&)'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.