mp3 shield invalid library compiling issue.

Hi there, first time user. Successfully tested my board with the "blink" function and it worked.

Trying to use the MP3 shield that wife bought me. I think Ive overcome the issues of importing libraries as they now appear in my sketch menu but upon trying to compile the sample test code for the shield I get errors which in my very limited experience, seem to relate to variable that are defined in the library themselves needing to be made constant.

//

Arduino: 1.8.4 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/jamesbaverstock/Documents/Arduino/libraries/SFEMP3Shield/SFEMP3Shield.cpp:25:37: error: variable 'bitrate_table' must be const in order to be put into read-only section by means of 'attribute((progmem))'
PROGMEM uint16_t bitrate_table[15][6] = {
^
/Users/jamesbaverstock/Documents/Arduino/libraries/SFEMP3Shield/SFEMP3Shield.cpp: In member function 'uint8_t SFEMP3Shield::vs_init()':
/Users/jamesbaverstock/Documents/Arduino/libraries/SFEMP3Shield/SFEMP3Shield.cpp:235:34: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
if(VSLoadUserCode("patches.053")) return 6;
^
exit status 1
Error compiling for board Arduino/Genuino Uno.
Invalid library found in /Users/jamesbaverstock/Documents/Arduino/libraries/libraries: /Users/jamesbaverstock/Documents/Arduino/libraries/libraries
Invalid library found in /Users/jamesbaverstock/Documents/Arduino/libraries/libraries: /Users/jamesbaverstock/Documents/Arduino/libraries/libraries

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
//

Any help would be greatly appreciated. Feel dumb not being able to get someone else's code that works to run.

Any help would be greatly appreciated.

Have you googled either of the messages?

error: variable 'bitrate_table' must be const in order to be put into read-only section by means of 'attribute((progmem))'

One of the disadvantages of using #define statements to make life "easier" is that it is then difficult to understand what the compiler it trying to tell you. If the message was

error: variable 'bitrate_table' must be const in order to be put into read-only section by means of 'PROGMEM'

would that be clearer?

Somewhere in the declaration of the bitrate_table variable, you need to use the keyword const. You may need to try more than one position.

warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

This is a warning, not an error.

Post your code, in code tags please.

It looks like some of your issues are that the library you're using was written before the arduino IDE was so fussy about const. I'm not sure whether gcc's defaults have changed or whether there was a change in the compiler flags the IDE uses. If it's the latter, you may be able to get better results with an older version of the IDE. The alternatives are to fix the library yourself - a tricky undertaking at your present level of experience, or to find a more up to date version of the library.

I have little to no idea.
I tried using the “find” function to locate the errors in the code with no luck.

Maybe someone more versed in code reading could point me to the area of trouble.

Thanks all for the help.
Much appreciated :slight_smile:

does code tags mean"``"?

I would love to however I’m not sure which bit of the code is needed.

Maybe someone more versed in code reading could point me to the area of trouble.

As in reply #1?

thanks for your help PaulS.

great news. Code compiling and uploading. Can now play mp3s from keyboard input.

Am now trying to figure out why I cant use my infrared sensor as the trigger to play. Code compiles, runs, detects motion and a high pitch sound (at very low volume) is emitted at the time a track should play.

Will k.b.o but much appreciative of expert help. wont just do bulk copy paste but I think the example code is incomplete, or was wondering if the baud rate of the two decices needs to be identical. The MP3 Shield is 115200? and the IR sensor is 9600. I’d presumed that one just uses the lowest of the two.

#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h> 
#include <SFEMP3Shield.h>

SdFat sd;
SFEMP3Shield MP3player;
 
               // choose the pin for the LED
int inputPin = 5;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
int randFile; //random number variable
 
void setup() {
  
    //start the shield
  sd.begin(SD_SEL, SPI_HALF_SPEED);
  MP3player.begin();
  
  pinMode(inputPin, INPUT);     // declare sensor as input
 MP3player.setVolume(10,10)
 
  ;Serial.begin(9600);
}
 
void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    
   
    MP3player.playTrack(001);
   
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
   
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
     pirState = LOW;
    }
  }
}

credit to Allen Pitts who wrote the code I’m dismembering with no knowledge of what the hell I’m doing. Am reading as much as I can in evenings and watching a few YouTube tutorials and I’m understanding the basic composition of the sketches but unsure if the order that things are declared or used/referenced is critical.

The MP3 Shield is 115200? and the IR sensor is 9600.

That is nonsense. The MP3 shield is an SPI device. It does NOT use Serial, so baud rate is completely irrelevant. The IR sensor is not a Serial device, either.

 MP3player.setVolume(10,10)
 
  ;Serial.begin(9600);

More nonsense. The ; goes at the end of the line, not two lines later in front of other code.

The whole block of code dealing with pirState is useless.

Thanks for the tip. I did manage to find a human to assist. Between us (mostly him walking me though it) the code we had has been rewritten and is simplified, compiling and working. I’ll attach the code (another one we found) it had no Author notes so I’ve credited the editing of this version to the person who gave me a hand and what little I did. I have tried to comment the life out of it to assist another dummy like me who thinks that anyone can get into arduino, hey ho live and learn. Thanks all for the messages of help, support or pointing out my mistakes, they all helped make the journey as valuable as it’s been.

[code]
//Edited by Paul Calder with little help from James Baverstock 8 September 2017

// libraries

#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>


//initialize
SdFat sd;
SFEMP3Shield MP3player;

// constant variables

int pirPin = 5;                       // PIR sensor input pin
int calibrationTime = 10;             // how long to calibrate the sensor for
int readingInterval = 20;             // how often to read the sensor

// changing variables

int rantrack = 7;                    // number of tracks on SD card this variable is the only one to be changed when adding tracks
byte result;                         // variable for mp3 player shield, can be used to debug

// setup

void setup() {
  pinMode(pirPin, INPUT);                         // make PIR sensor an input
  digitalWrite(pirPin, LOW);                      // activate internal pull-up resistor
  //give the sensor some time to calibrate
  for (int i = 0; i < calibrationTime; i++) {
    delay(1000);
  }
  result = sd.begin(SD_SEL, SPI_FULL_SPEED);        // SD card setup
  result = sd.chdir("/");                           // navigate to root directory of SD card
  result = MP3player.begin();                       // start mp3 player shield
  //MP3player.setVolume(0, 0);                      // set volume of the mp3 player ( 0 = loudest )
}

// loop

void loop() {
  if (digitalRead(pirPin) == HIGH) {               // if movement sensed
    if (MP3player.isPlaying() == 0) {               //check if an mp3 is playing and if so, do nothing.
      MP3player.playTrack(random(1, rantrack+1));   //play random track from one to one over the number in the rantrack variable exclusive
    }
  }
  MP3player.available();                           
  delay(readingInterval);                          // wait with reading
}

[/code]

i have a similar problem. only get the message: "invalide library ....." and it looks like Arduino IDE will not recognize the SFEMP3Shield library. Did not really understand how you solved this and got it to start compiling and uploading again....
Best
Pål Asle

only get the message: "invalide library ....."

A library is supposed to supply a file that defines the category that the library fits in. If that file is missing, or the category is not understood, you get the invalid library message but the header and source files are still included and compiled, as needed.

If you are having problems, post your code and the EXACT error messages. Do NOT try to paraphrase the messages. The details matter, a great deal.