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.
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;
^
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.
@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.
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.
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!
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.
@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.
@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!
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?
@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.
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.
@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.