Adafruit VS1053 (mp3) library for music maker shield ported?

Hi @peekay123,

Well, I tried it with the “old” SD library and that gave the same “hiccup” problem. I am waiting for my 2nd shield, so I can continue working on getting this fixed.


@RolfHut, while waiting for the new breakout, can you tell me which values you assigned to these in player_simple.ino:

#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Can I assume you connected DREQ from the breakout to a core pin?

Hi @peekay123, I am using the following:

// These are the pins used for the breakout example
#define BREAKOUT_RESET  D6//9      // VS1053 reset pin (output)
#define BREAKOUT_CS     A2//10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    D5//8      // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_CS     D4//7      // VS1053 chip select pin (output)
#define SHIELD_DCS    A7//6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS D3//4     // Card chip select pin
// DREQ should be an Int pin, see
#define DREQ D0//3       // VS1053 Data request, ideally an Interrupt pin

Does that help?


@RolfHut, the pins look good so no issue there. I believe the things to look for include the SPI clock speed and in use of enable/disable interrupts (cli/sei) in the library. Keep me posted on your progress. :smile:

I’ve finally had some success with this. I had to specify all the SPI pins (ie use software SPI):

#define MOSI  A5
#define MISO  A4
#define CLK   A3

#define BREAKOUT_CS     A2

#define DREQ            D0
#define BREAKOUT_DCS    D2
#define CARDCS          D3

Adafruit_VS1053_FilePlayer musicPlayer = 

and the same when initialising the sd card


I’ve only tried musicPlayer.playFullFile so far. Next up background playing…

@zeroyellow, that may indicate that the hardware SPI clock is set too high or too low. In line 461 of Adafruit_Vs1053.cpp, try changing the clock to SPI_CLOCK_DIV256 (slower at 140,625Hz) or SPI_CLOCK_DIV64 (faster at 562, 500Hz) to see if you get better results.

The Arduino is set for DIV128 which is 128,000KHz. The closest Spark value is DIV256.

For your tests, keep the SD on software SPI and try hardware SPI on the VS1053. There may be conflicts between the two on the hardware SPI bus though I’m not sure why at this time. Keep me posted :smile:

Hi all,

thanks all for your continued effort in this. As mentioned earlier, I do not have time currently to work on this, but will continue this over the christmas break. The project that I needed this for, is now finished. Result will be published in (dutch) newspaper tomorrow. Unfortunatly, it’s behind a paywall, so can not share here.

However, I entered the project in the instructables “enchanted objects” competition, so you can see the result here:

For the Dutch on this community, it is in the Volkskrant Newspaper, in the Sir Edmund part.


@RolfHut, nice job! I did not know that the Serial.print() debug messages affected the code. Any chance you can give a little nod to the Spark Community in your instructable? :wink:


Hi @peekay123,

I should have done that indeed, and will edit it!



For me, some weird things are happening:

I’ve setup the library like this:

#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 "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)

// These are common pins between breakout and shield
#define BREAKOUT_CARDCS D3//4     // Card chip select pin
// DREQ should be an Int pin, see
#define DREQ D0//3       // VS1053 Data request, ideally an Interrupt pin


And I use the following commands to play (every 30 seconds in the main loop):

musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int  

The music would never start unless I’m removing the SD card once and insert the card again - from then on it will work all the time.

Any ideas?

Well actually it seems that you should put:


in the setup method …

Actually - I guess the whole MusicPlayer init block should be in the setup method - have moved everything there (+ added a small “isInitialized”-flag in case the init fails) and now it is working beautifully - interrupt play, normal play, stop, pause, setting volume - great!!!

1 Like

Would you mind posting a picture of what your wiring looks like? I’m still having trouble getting the Core to recognize the shield.

@mmoderwell I don’t have mine available to take a pic now but if you post a pic of your’s I’ll see if I can spot anything.

Two things that got me. I had the miso and mosi lines mixed up at first. Try swapping them and see if that helps.

Also I sometimes had issues with the power to the board when powering the whole thing via usb. Sometimes I would have to disconnect power to the vs1053 board while I reset the core then reattach the power before it started up. I don’t get this problem running on batteries.

@peekay123 sorry for the slow response.

I don’t have the board at the moment so I can’t run the tests. If I get my hands on it again I’ll be sure to though.

I was able to get the vs1053 to play a test tone with hardware SPI so I don’t think it’s the clock.

I’m pretty sure the problem is you loose control of the cs pin when running on hardware SPI. So whenever you try and use the bus the vs1053 is signalled, even if you’re trying to talk to the sd card.

I suspect that running the vs1053 on the hardware bus and sd on separate software bus as you suggested would work. Although it would also use more pins.

@mmoderwell I can’t see anything wrong but it’s a bit hard to trace the connections. I did manage to find a pic of my setup before I transferred it to perf board. I’d changed the pins around so as many as possible lined up so I had less to solder.

#define MOSI  A5
#define MISO  A6
#define CLK   A4

#define BREAKOUT_CS     A2

#define DREQ            A7
#define BREAKOUT_DCS    A0
#define CARDCS          A1

Adafruit_VS1053_FilePlayer musicPlayer = 

// then call these two from setup
int initPlayer(){
    playerInitialised = musicPlayer.begin();
    return playerInitialised;
int initSdCard(){
    return sdCardInitialised = SD.begin(MOSI, MISO, CLK, CARDCS);

If you’re sure all your wiring is correct and you have the right pins defined in your code, try putting a ten second delay at the start of your setup, disconnect the power to the vs1053, restart the core and then reconnect the power during the 10 second delay.

@zeroyellow thank you for all your help so far. I have adjusted my wiring to be like yours. You included an excerpt of your code but I can seem to find a way to get it to work with what I have. Would you mind including a little more? All I’m trying to do is play a simple MP3.

@zeroyellow, part of the problem with using the VS1053 library is that is has a lot of “options” to use:

***** Two interrupt options! *****
musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); //Timer interrupt
This option uses SparkIntervalTimer (timer2) with 1ms interrupt

musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
This option uses a pin interrupt. No timers required! But DREQ
must be on an interrupt pin. For Spark Core, those are pins:
D0, D1, D2, D3, D4 A0, A1, A3, A4, A5, A6, A7

!!! This method is preferred !!!

In both cases, the interrupt service routine calls feeder() which in turns calls feedBuffer(). This function reads a buffer full of data (32 bytes) from the SD card then writes it out to the VS1503. With hardware SPI, these reads and writes do not overlap and will not conflict, primarily since hardware SPI operations block until they are complete. Unless you are using SPI for other peripherals, there will not be any conflicts. If you ARE using other SPI devices, you will need to disable interrupts during your SPI transactions to avoid conflicts with the VS1503 interrupts.

The player_simple example is setup for hardware SPI and DREQ interrupts. I updated the file to include a SPARK specific pin assignment section. In this scenario, the Core hardware SPI pins are used and DREQ is put on an interrupt capable pin.

One area I could not explore in the port is the SPI clock setting in the VS1053 begin() function. It is presently set to SPI_CLOCK_DIV128. For Arduino, that gives an SPI clock of 125KHz. From the specs and the Adafruit schematics, it looks as if the maximum SPI clock speed is 1.5MHz! For the Core, that requires a setting of SPI_CLOCK_DIV32. So it may be worth exploring this as the SPI clock affects both the VS1053 and the SD card.

Looking at the entire library and the examples, both the VS1053 and the SD begin() functions set the SPI clock to different values. The SD code, which is called after the VS1053 begin() code, sets the clock to DIV8, which is too high for the VS1053. A quick fix for this issue is to do a SPI.setClockDivider(SPI_CLOCK_DIV32) after the SD.begin() call to reset the SPI speed to work with both the VS1053 and the SD (albeit at a slower speed). You will need to experiment with this to see what the highest SPI clock speed you can use for the VS1053. Keep me posted. :smile:

You might want to try my fork which you can find at

It already include die SPI-clock divider which works at least for me using MP3s - I’m having troubles playing WAV-files though - but the VS1053 does only support a couple of WAV codecs, bitlengths etc. - maybe that’s the problem.

I’ve also added a new sample called sparkplayer.ino -

If you are using the WebIDE , I’ve also added the VS1053 library to the WebIDE moments ago …

1 Like

@McTristan, your library still has the issue that SD.begin will set the SPI to DIV8, overriding the DIV256 of the VS1053 begin(). A quick fix is to change the SPI.setClockDivider() in S2dCard.cpp line 232 to DIV256. I would also try setting it to DIV32 since the VS1053 should be able to handle a 1.5MHz SPI clock.

1 Like