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

Has anyone ported the adafruit vs1053 library? I am converting a project that I have functional with an arduino Uno + wifi shield + music maker shield, to work with my spark, because I want to use the easy online tools that the Spark offers. Having looked at other examples of ported libraries, I have no idea where to start with porting the the vs1053 library. I’ve tried adding it straight to the project in Build, changing around the other libraries that the vs1053 library includes, but that leads to unspecified types when compiling.

any help is greatly appreciated.

the VS1053 library can be found in this repo: https://github.com/adafruit/Adafruit_VS1053_Library

thanks in advance,

Rolf

PS I am using the shield-shield to connect music maker to spark.

2 Likes

Hey @RolfHut,

seems like no one has picked this up yet so i’ll see how best i can help.

1.) We might be able to make do without the shield shield but let’s keep it there for now

2.) I will try compiling this and see how far i can go and reply here once there’s some progress :wink:

I tried the porting and it’s using very Arduino specific code that makes it really hard to port.

Adafruit_VS1053.cpp: In constructor 'Adafruit_VS1053::Adafruit_VS1053(int8_t, int8_t, int8_t, int8_t, int8_t, int8_t, int8_t)':
Adafruit_VS1053.cpp:252:56: error: 'digitalPinToPort' was not declared in this scope
   clkportreg = portOutputRegister(digitalPinToPort(_clk));
                                                        ^
Adafruit_VS1053.cpp:252:57: error: 'portOutputRegister' was not declared in this scope
   clkportreg = portOutputRegister(digitalPinToPort(_clk));
                                                         ^
Adafruit_VS1053.cpp:253:36: error: 'digitalPinToBitMask' was not declared in this scope
   clkpin = digitalPinToBitMask(_clk);
                                    ^
Adafruit_VS1053.cpp:254:58: error: 'portInputRegister' was not declared in this scope
   misoportreg = portInputRegister(digitalPinToPort(_miso));
                                                          ^
Adafruit_VS1053.cpp: In member function 'void Adafruit_VS1053::setVolume(uint8_t, uint8_t)':
Adafruit_VS1053.cpp:380:7: error: 'cli' was not declared in this scope
   cli();
       ^
Adafruit_VS1053.cpp:382:7: error: 'sei' was not declared in this scope
   sei();
       ^
Adafruit_VS1053.cpp: In member function 'uint16_t Adafruit_VS1053::decodeTime()':
Adafruit_VS1053.cpp:386:7: error: 'cli' was not declared in this scope
   cli();
       ^
Adafruit_VS1053.cpp:388:7: error: 'sei' was not declared in this scope
   sei();
       ^
Adafruit_VS1053.cpp: In member function 'void Adafruit_VS1053::GPIO_pinMode(uint8_t, uint8_t)':
Adafruit_VS1053.cpp:516:18: error: '_BV' was not declared in this scope
     ddr &= ~_BV(i);
                  ^
Adafruit_VS1053.cpp:518:17: error: '_BV' was not declared in this scope
     ddr |= _BV(i);
                 ^
Adafruit_VS1053.cpp: In member function 'void Adafruit_VS1053::GPIO_digitalWrite(uint8_t, uint8_t)':
Adafruit_VS1053.cpp:537:19: error: '_BV' was not declared in this scope
     pins &= ~_BV(i);
                   ^
Adafruit_VS1053.cpp:539:18: error: '_BV' was not declared in this scope
     pins |= _BV(i);
                  ^
Adafruit_VS1053.cpp: In member function 'bool Adafruit_VS1053::GPIO_digitalRead(uint8_t)':
Adafruit_VS1053.cpp:555:18: error: '_BV' was not declared in this scope
   if (val & _BV(i)) return true;
                  ^

Sorry!

Hi Kenneth,

super, really appreciate your help/work. I also run into the PinToPort mapping issue and that is were I got stuck: not enough embedded knowledge to proceed :-s.

For now I have my setup working by having an additional arduino next to my spark: the spark & arduino communicate simply by a single pin being high/low, which triggers the arduino to play a single sound file. However: I started this project to show how the Spark could do what an arduino does and then some. If you can get the VS1053 lib to compile, I would be very thankful!

best,

Rolf

PS project overview: on button press by user the spark starts a music file on the VS1053. Whilst playing, it makes an API call to a remote server, parses the response and finally, using a EMIC2, speaks the response back to the user. specifics about API and what it is all about will be revealed as soon as projects works, is uploaded to instructables & this forum and is featured in the (dutch) national newspaper in which I write a monthly column.

1 Like

@RolfHut, the library uses the SD library which has too many files to put on the IDE. I can port the code but you would need Spark CLI to compile it. It may take a few days. :smile:

@peekay123 I have all the files in a directory just short of fixing the Arduino specific code if you need :slight_smile:

2 Likes

Hi Kenneth, sound great! anything I can help with?

Rolf

I am working on the port but first I have to address an issue with SparkIntervalTimer interrupt priorities. Once that’s done, I can finish the port. :smile:

I’m working with the same breakout. Can’t wait till you guys get something going! Thanks for all your hard work.

1 Like

Folks, the porting is done and I’ve added the SparkIntervalTimer stuff to use the hardware timer when the compiler directive is selected. Everything is compiling but I will leave testing to those who have the shield. I’ll be posting the library on my github tonight. :smile:

5 Likes

great! I will start testing it (my, european) tonight!

I had a couple of laptop issues but finally, here is the complete github repo for the VS1503. All necessary library files are included, including a slightly updated SparkIntervalTimer (fixed interrupt priority).

The Arduino SPI clock is set to DIV128 though the boards should be able to take a higher clock so the DIV8 I selected may need to be set to a slower clock (DIV16, DIV32). Testing will tell. Please let me know how it goes! :smile:

Hi @peekay123

thanks for al your work! I spend the last two night testing it and run into some problems.

  • It does not compile when using all your files. Something goes wrong in the SD library that you added: I get the error that a function is declared twice.
  • However, if I only add the files Adafruit_VS1053.h and Adafruit_VS1053.cpp from you and add the sd-card-library from the libs available in build, the example code does compile and works! However:
  • the sound is wrong: there is little hiccups in it. I guess this is what your SparkIntervalTimer is supposed to fix.

Finally: I changed the simplePlay example to get rid of the “while(1)” statements. Those may be great for Arduino’s, but they make sure the Spark get disconnected from the cloud and can only be brought back by a firmware reset. I have created a pull request to your git-repo for this lib for that example file.

Hope you can find the bug in the SD part.

thanks again,

Rolf

@RolfHut, I test compiled the code using Spark CLI as I find the IDE difficult to develop in. The new Spark DEV is showing huge promise also. There are several modes, it seems, to run the VS1503 in. One is using IRQs from the shield, another is using the interval timer and the last is polled I believe. Make sure you understand how you’ve configured the necessary #defines to get the mode you need. :slight_smile:

Hi @peekay123, I’ll work on it tonight. given the example code I send you: any suggestions on where I go wrong?

thanks

Rolf

@RolfHut, it seems that some of the Spark adaptations did not make it to the examples. I’ll merge your PR and make sure the changes I have on my local repo get updated on github for the other examples. Let me know how it goes and thanks! :smile:

hi @peekay123,

I installed CLI (and DFU, what a time-saver!) to test it. I now run into this: my code nicely compiles using the CLI (I put my .ino example file in the same dir as all the library files). However: after uploading, my spark can not find my VS1053. (ie, when calling begin() on Adafruit_VS1053_FilePlayer object, it returns an error (unspecified). Weird thing is: when I use the “official” sd library (ie. 0.0.1 current release in Spark Cloud IDE) and only use your Adafruit_VS1053.h and Adafruit_VS1053.cpp (and have those also include the “official” sd-library), I get it to recognise the the shield and play sound, but then I do run into the timming issue: hiccups in my playback. Exactly the thing you aim to fix in your version.

Hopefully this helps you to pinpoint what is going wrong. First idea from my side: has anything changed in the way that you deal with the sd? Do I need to call files differently? Or does it pose restrictions? Other thought: do you assume something on the way / pins that SPI are connected?

Hope you can help me out!

thanks in advance,

Rolf

@RolfHut I’m following along and not having much success either, less than you in fact.

I wonder if the skipping is due to the fact that the you’re calling playFullFile which doesn’t return until the it’s finished playing and the spark likes to have Spark.process called regularly which wouldn’t happen while the file was playing. Did you try startPlayingFile instead?

@peekay123, thanks for your work porting this. It’s really appreciated.

1 Like

Hi all,

I’ve been working on it, but couldn’t get it to work before my deadline. I used the spark for the first part of my project and linked it to an arduino for the second part. I will post the instructables link and newspaper article here as soon as they are published.

I have ordered a second music maker shield, so I can keep working on this port. During the christmas holidays I will have time to do so and hopefully can get this to work. If anyone else gets this to work in the meantime, I am of course more than happy to hear about that.

thanks for all the input / help so far,

Rolf

@RolfHut, did you try using the board without enabling the hardware timer? I am trying to figure out if its a problem with using SparkIntervalTimer or if the issue is somewhere else in the code.