Adafruit VS1053 Codec + MicroSD Breakout - MP3/WAV/MIDI/OGG Play + Record - v4 #891
Replies: 57 comments
-
Posted at 2014-11-16 by DrAzzy Looks like it'd be easy to port the arduino library code, just looking at the code. One nice thing with C and JS is, you can copy/paste most C (particularly arduino C which doesn't do much weird stuff ) into something that does JS syntax highlighting, and the basic structure will be valid JS - you just have to change the variable declarations, and rewrite the parts that are different between arduino and espruino (like SPI, which is way clunkier to use on arduino) Though, often there is room for improvement after this. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-11-17 by @gfwilliams Just to add that you should probably just ignore the SD card and use Espruino's built-in one for now. I will be adding support for SD cards on pins that you supply, but that'll be a month or two away. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-11-17 by DaveNI SD card support on pins would be excellent - it would mean Pico could make use of the SD card reader that comes on the ILI9341 display boards. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-11-17 by @gfwilliams
That's the plan :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-01 by andri Any progress or update about this guys? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-12-01 by @gfwilliams Well, Espruino has supported SD cards on arbitrary pins for almost a year now - but as far as I know nobody has posted up any code to use this module. Ad @drazzy said initially, it looks quite easy though - you just have to send the right stuff over SPI to set it up (which you could steal from Adafruit's library) and then you just read chunks of data off the SD card and write them down SPI - it's really only a few lines of code. We can't write the module for you as we don't have one of those decoders here, but we can definitely lend a hand if you need any help. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-28 by pwhitrow Just purchased a PIco last week and been playing around, this thing rocks! I have lying around the VS1053 as stated above, but have no idea what I'm doing with SPI etc! ANY help would be appreciated... I simply want the pico to be able to select any track on the SDcard, but don't know where to start! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-28 by @gfwilliams As far as I can tell, the chip doesn't read the SD card itself - that'd be up to Espruino... So a good start would be to use the info here to try and wire the SD card up and get it working. After that, it'd be best to try and reproduce Adafruit's library in Espruino. You can pretty much replace the It could be a bit of a slog though - it'd be worth trying to implement something like the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-28 by pwhitrow Thanks Gordon for the fast reply. This might blow my head but I'll give it a go. I also have the Sparkfun audio breakout board (https://www.sparkfun.com/products/11125) which supports a 2-Wire (Data, Clock) interface to any micro-controller, so I'm thinking this may be easier to drive from the Pico? Do you have any code examples to help me get started? If i get it working I'm happy to share back to the community. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-29 by @gfwilliams Yes, the Sparkfun board would definitely be easier! But to get started with the Adafruit one, use the first example on the File IO page linked above:
(and try wiring the SD card as shown above) For the Sparkfun board their code is a good start: https://github.com/sparkfun/Audio-Sound_Breakout-WTV020SD/blob/V_1.0/firmware/Audio-Sound_Breakout/AudioModule.ino Just replace
Also, you know that Espruino can do sounds itself? http://www.espruino.com/Waveform It may not be significantly worse quality than the Sparkfun board :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-29 by pwhitrow Hey bud, thanks for this. I did see that Espruino can do native sounds but as I'm dealing with larger sounds files in mp3 format I assumed a breakout board was the way to go. However, after looking at the Wavefom page I'm wondering if I should just resave the mp3 in raw format and stream directly from the sdcard using the code on that page. Still fumbling my way through this as I stopped doing electronics over 20 years ago and am now on a very steep learning curve with the new ways of doing things! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-29 by @gfwilliams Yes, if you're not after high quality you could definitely stream from SD card for however long you wanted. I guess it might be worth a try first to see if that'd do you - it would be a lot more simple to wire up! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-29 by pwhitrow will do, thanks Gordon. Loving the Espruino, amazing work fella. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-09-30 by pwhitrow Hey Gordon, I have the 1.4 Espruino now and have tried to stream a converted raw file from the sdcard, but all I'm getting is a high pitched whine. I used the code here: http://www.espruino.com/Waveform var f = E.openFile("1.raw","r"); var w = new Waveform(2048, {doubleBuffer:true}); Any help would be appreciated. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-02 by pwhitrow OK, done some more digging and trying some other code (found here: http://forum.espruino.com/conversations/277322/): var wave = fs.readFile("/audio/static/1.raw"); The file is only 17k in size but I'm getting an Out of Memory error ... ??! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-06 by pwhitrow I give up! It was so close to working, was able to select and play files off the card, but now for apparently no reason as I've not added anything, it constantly runs out of memory and falls over playing a file. I see my only options now as either hooking up a dedicated mp3 player breakout (with sdcard), but I have zero idea of where to start with this (want to be able to control and select the file being played but can't find any info in the forums or main pages that I can make sense of) or drop Espruino and try to learn Ardiono as it seems to be more suited for this sort of thing (really don't want to do this). As a wise man once said, it's only easy when you know how. I'm open to any and all advice at this point! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by @gfwilliams Does it fail even with the second section of code I posted above? Perhaps you could strip your code down to a bare minimum that still exhibits the problem and that you can post up here? Then we can run it and see what's wrong. It may not even be related to playback - it might be the rest of your code that's allocating memory somewhere. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by @gfwilliams Just to add, you can run something like |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by pwhitrow Was using the code from above, and it was working for a bit but now falls over with some larger files. All the other code is running as expected and presents no memory error. I'll give your above suggestion a try and see if I get any information. Was also looking at hooking up the VS1053 break out mp3 player, but no having much luck with that either. I'm assuming it's down to having an sdcard already on the Espruino 1.4, as I get a NOT_READY response from it when I hook up the VS module to SPI2 (LCD is on SPI1) and try to connect to it with E.connectSDCard. I'm assuming it's due to the require('fs') only reading teh onboard sdcard so tried separating them and assigning as unique, but no dice.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by @gfwilliams I've spent hours so far helping you get your code working. I've posted code above (at the end of last post) that I just tested, and that is working perfectly, without any loss of memory. In fact you could use the code below, which allows you to just call
I'm afraid I just don't have time to help you throw everything away and start again from scratch, especially when I offered to fix your code and you can't be bothered to strip it down enough that you can post it up for me. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by pwhitrow Dude, I didn't mean to piss you off. I have to be careful with the code I post so I can protect the IP of the product being developed. I have tried to implement your suggestions and have fed back results. I very much appreciate all your help Gordon, and have expressed that. I understand how busy you must be and how annoying constant questions are from a "newbie" who doesn't have as much knowledge of the subject matter as yourself, I get that in what I do, so I'm trying to structure help requests and feedback on implementing your suggestions as well as I can. In a previous post I did ask if I could send you the entire code "as is" to your email (for security reasons) rather than listing it all here, so that you could see the full structure as opposed to snippets but had no response from that so have had to keep posting piecemeal bites of code. I apologise if this approach has angered you. I don't recall an offer to fix my code if I'm honest but maybe I missed that or misread a post, and neither did I ask you help me start again from scratch. I have stripped down what I believed to be the relevant parts and posted them for you, so to hear you say I couldn't be bothered is a little unsavoury. I did also say I was open to suggestions and if that is "go away and don't bother me again" than so be it. Thank you for your time thus far. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by @gfwilliams Sorry for the misunderstanding - it just seemed from the previous post that you were starting off on the VS1053 player when you were so close to getting the existing one working. Sure, if you email the code to [email protected] that's fine, and I'll take a look and see if I can figure out what's using up the memory. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-07 by pwhitrow Thank you mate, I VERY MUCH appreciate it |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-24 by @gfwilliams Ok, so I just looked at your code, and it looks like you'd disabled playing sound in it? I had to remove a return statement in playSoundFile. I'll post up here as I think it's useful for everyone though. Also just a note - I'd avoid putting I got the out of memory error you were having, but I think that's because just because you were using up all the memory rather than an actual bug in your code. If I deleted the two images and drawImage statements you had it seemed pretty reliable (I'd also replaced the DS18B20 code with Memory goes up a bit when playing, and then drops off when it's finished - but it always goes back to the same base level after startup, and it's been working for about an hour now without issues. So it's basically just a matter of making your code use a bit less space...
Hope that helps - but yeah, I think you're basically fine. If you absolutely need more then there's always the Pico - it'd need more wiring but it does have a bit more RAM. There's also the WiFi board too, which has even more RAM available. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-24 by pwhitrow Thanks for taking the time G. I got to thinking I may have reached the memory limit, hence stripping the code back as much as I could. The return statement was in there as a debug thing, just so it didn't fall over and I could continue to develop the rest of the features while looking for a solution :) I did look at using the internal temp sensor as opposed to DS18B20, and I still might revert back. Although, both seen to be around 10 degrees higher than the thermometer I have. Although not critical, it would be nice to have better accuracy. The images may have to go then, although they are small (icon size). Would it better to call these in from the SD card, or will that still take up valuable memory space? I'll keep playing with some of your other recommendations and see where I can get to. I did start out with the Pico, but as I'm using all (and may need more!) of the IO pins, I switched to the larger Espruino (especially as this has the onboard SDcard). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-24 by @gfwilliams I think with the ideas above you should be fine for a while, even with DS18B20 and images - it basically halves your memory consumption minifying and saving to flash. Loading images from flash (especially if you have more) could be good - as would Also, for DS18B20 it's better to use a callback for the temperature: http://www.espruino.com/DS18B20 Using a normal function is the older way, but it means that your temperature readings are always from the previous call to |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-24 by @allObjects
@pwhitrow, I do not know what kind of io pins you need, but did you ever think of port expander (s)? They are extremely flexible... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-24 by pwhitrow Thanks man, I'll add that page to my list of things to read (learn) .... I wish I could give further details too but have to protect the IP of the product so shooting blind with some of this. That said, loving what Espruino can do so far! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-25 by @allObjects Reading through @gordon's comments and suggestions, some of the history, and now the number of ports you serve, could it be that JS just does not get quickly enough its cpu cycles? - ...adding setSleepIndicator(pin) / setBusyIndicator(pin) to your code could provide this information. If you have streaks of long JS - with some 'weird' code - worst case looping until a pin status kicks in - interrupt serving in the JS layer is delayed... and refilling the buffers as well... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-25 by pwhitrow Thanks for your suggestions bud. It's actually working quite well now with G's suggestion to reduce the waveform buffer and seems to play all files. It does stutter occasionally but for this prototype stage I can live with that. Interesting thoughts on the cycles issue, will have to dig into that. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-11-16 by davenelson
Here is the product page:
https://www.adafruit.com/product/1381
And here is the tutorial:
https://learn.adafruit.com/adafruit-vs1053-mp3-aac-ogg-midi-wav-play-and-record-codec-tutorial/overview
I meant to buy one of the Audio FX boards and use the Espruino to trigger the FX Board, but I accidentally bought the VS1053 instead, not sure how I made that mistake.
Wiring it up looks pretty straightforward using SPI, but does anyone have any experience with the programming side of it? There are Arduino libraries available in the tutorial, but I would prefer to use it with the Espruino as part of my first project.
Beta Was this translation helpful? Give feedback.
All reactions