It is kind of weird … I have a couple of mp3 files which the player does not like to play in the background… I can play long songs usually without any problems and lighten up a couple of LEDs from the main loop - no problem. But for particular mp3s it seems something is blocking the mainloop until the mp3 finished playing.
It seems to happen always with the same files and I can’t figure out what it is …the length does not seem to be important as longer mp3s do also work while others (but always the same others) do not …
I’ve even removed all additional calls from the main loop but it even seems subscribed events, external function calls (i.e. over the cloud) won’t be processed at all… it’s completely blocking but playing music …
this happens on two different core at the same time (don’t ask ) so it is no coincidence …
@McTristan I had a strange blocking problem as well. The core would intermittently hang for 20 seconds or more, although it didn’t seem specific to certain files. I fixed it in the end by disabling interrupts at the end of my loop function and re-enabling them at the start. It might not be the same problem you’re seeing but perhaps worth a try.
void loop(){
// reenable interrupts so we can play the audio
interrupts();
// do your stuff here
...
// disable interrupts while the spark is talking to the cloud because othewise it can hang for quite a while
noInterrupts();
}
I have these blockings you mention also from time to time, good to know there is a workaround… However, the blocking I have seems to be dependent on certain songs…
Strange…
I’ve tried the suggested fix but it does not help me with my specific problem - the whole core is still blocking while playing particular files (that’s also the reasons I haven’t yet published the library again)
I’m trying to get the VS1053 working but I’m having a bit of trouble. I imported your library and flashed sparkplayer.ino. I believe I have all the connections correct, but it’s still not working. Could you elaborate on how I can go about setting up a simple play of one mp3 file?
// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_VS1053/Adafruit_VS1053.h"
// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_VS1053/SD.h"
// define the pins used
#define BREAKOUT_MOSI A5 // Output data, to VS1053/SD card
#define BREAKOUT_MISO A4 // Input data, from VS1053/SD card
#define BREAKOUT_CLK A3 // SPI Clock, shared with SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"
// These are the pins used for the breakout example
#define BREAKOUT_CS A2//10 // VS1053 chip select pin (output)
#define BREAKOUT_RESET D6//9 // VS1053 reset pin (output)
#define BREAKOUT_DCS D2//8 // VS1053 Data/command select pin (output)
#define STANDARD_VOLUME_LEVEL 0
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(BREAKOUT_MOSI, BREAKOUT_MISO, BREAKOUT_CLK, BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, BREAKOUT_CARDCS);
int currentVolume = STANDARD_VOLUME_LEVEL;
void setup() {
SD.begin(BREAKOUT_MOSI, BREAKOUT_MISO, BREAKOUT_CLK, BREAKOUT_CARDCS);
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
} else {
Serial.println(F("VS1053 found"));
}
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
// musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working
}
void loop() {
}
int playSong(String command)
{
char filename[255]; // Or something long enough to hold the longest file name you will ever use.
command.toCharArray(filename, sizeof(filename));
musicPlayer.setVolume(currentVolume,currentVolume);
musicPlayer.stopPlaying();
musicPlayer.startPlayingFile(filename);
return 1;
}
You just call the playSong method - make sure you are not doing in the main loop without a delay or such thing as it will play the song in the background - I’m mainly using spark cloud events for playing sounds and this works well … I have also multiple VS1053 modules and they all work fine …
sorry to have dropped out of the conversation. Seems like you have this al worked out: very nice! Will work on sound based projects soon again, so very greatfull for the community running with my initial request.
Thanks for the help. I’m still having trouble. Here’s the code.
// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_VS1053/Adafruit_VS1053.h"
// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_VS1053/SD.h"
// define the pins used
#define BREAKOUT_MOSI A5 // Output data, to VS1053/SD card
#define BREAKOUT_MISO A4 // Input data, from VS1053/SD card
#define BREAKOUT_CLK A3 // SPI Clock, shared with SD card
// Connect CLK, MISO and MOSI to hardware SPI pins.
// See http://arduino.cc/en/Reference/SPI "Connections"
// These are the pins used for the breakout example
#define BREAKOUT_CS A2//10 // VS1053 chip select pin (output)
#define BREAKOUT_RESET D6//9 // VS1053 reset pin (output)
#define BREAKOUT_DCS D2//8 // VS1053 Data/command select pin (output)
#define STANDARD_VOLUME_LEVEL 40
// These are common pins between breakout and shield
#define BREAKOUT_CARDCS D3 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ D0 // VS1053 Data request, ideally an Interrupt pin
bool played_once = false;
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(BREAKOUT_MOSI, BREAKOUT_MISO, BREAKOUT_CLK, BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, BREAKOUT_CARDCS);
int currentVolume = STANDARD_VOLUME_LEVEL;
void setup() {
SD.begin(BREAKOUT_MOSI, BREAKOUT_MISO, BREAKOUT_CLK, BREAKOUT_CARDCS);
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
} else {
Serial.println(F("VS1053 found"));
}
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
musicPlayer.sineTest(0x44, 500); // Make a tone to indicate VS1053 is working
}
void loop() {
delay(5000);
if (played_once == false){
playSong("track001.mp3");
played_once = true;
}
}
int playSong(String command)
{
char filename[255]; // Or something long enough to hold the longest file name you will ever use.
command.toCharArray(filename, sizeof(filename));
musicPlayer.setVolume(currentVolume,currentVolume);
musicPlayer.stopPlaying();
musicPlayer.startPlayingFile(filename);
return 1;
}
I’m new to the spark core, am I calling the function correctly? The VS1053 is functioning and plays the test tone on start.
Hi all! I have an Adafruit VS1053 breakout and would like to use it to play mp3 streams from web radio stations. My code on the Core is more or less ready to receive Icecast streams and demux them to extract meta information and separate the mp3 stream.
I would not use the SD card on the VS1053 at all, and only use the playData method from the library, I guess. Do you think the ported library can be used as is, with hardware SPI?
(Sorry if this does not make sense, I am VERY new to Core development, and it is my first time to use the Adafruit VS1053 breakout or ANY SPI stuff for that matter…)
Hi all, I tried to compile the library (using the sparkplayer.ino example) by @McTristan for the Photon using the mac Build app, but I get 3 errors saying " ‘PIN_MAP’ was not declared in this scope."
Could anyone explain why this is happening and if there is a reason? I’m a real beginner, so any help would be much appreciated! Thanks