• 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.

  • 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.

  • 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.

  • 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.

  • it would mean Pico could make use of the SD card...

    That's the plan :)

  • Any progress or update about this guys?

    Thanks.

  • 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.

  • 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!

  • 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 spiwrite function with spi.write and you're good to go.

    It could be a bit of a slog though - it'd be worth trying to implement something like the sineTest function first...

  • 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.

  • 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:

    // Wire up up MOSI, MISO, SCK and CS pins (along with 3.3v and GND)
    SPI1.setup({mosi:B5, miso:B4, sck:B3});
    E.connectSDCard(SPI1, B6 /*CS*/);
    // see what's on the device
    console.log(require("fs").readdirSync());
    

    (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 sendCommand with something like:

    function sendCommand(command) {
      digitalWrite(DCLK, 0);
      setTimeout(function() {
        for (var i = 0; i < 16; i++) {
          digitalWrite(DCLK, 0);
          digitalWrite(DOUT, (command & 0x8000) != 0);
          digitalWrite(DCLK, 1);
          command = command<<1;
        }
      },2);
    }
    

    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 :)

  • 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!

  • 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!

  • will do, thanks Gordon.

    Loving the Espruino, amazing work fella.

  • 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});
    // load first bits of sound file
    w.buffer.set(f.read(w.buffer.length));
    w.buffer2.set(f.read(w.buffer.length));
    var fileBuf = f.read(w.buffer.length);
    // when one buffer finishes playing, load the next one
    w.on("buffer", function(buf) {
    buf.set(fileBuf);
    fileBuf = f.read(buf.length);
    if (fileBuf===undefined) w.stop(); // end of file
    });
    // start output
    analogWrite(A0, 0.5);
    w.startOutput(A0,11025,{repeat:true});

    Any help would be appreciated.

    Thanks.

  • 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 ... ??!

  • Which board are you using? An original Espruino, or a Pico?

    The original has a DAC on pins A4 and A5, all other pins have PWM (It looks like you copied the example but changed the pins?). If you don't specify a frequency for analogWrite on the PWM pins it'll use a default frequency which is a few kHz which will produce an audible whine. You could try: analogWrite(A0, 0.5, {freq:30000}); and that might fix it for you?

    It's surprising you get out of memory for a 17k file, but do you have much other code in the Espruino as well? IIRC fs.readFile doesn't use memory quite as efficiently as it could, but even so I'd hope it'd would have managed 17k.

    Still, hopefully the changes to analogWrite above will help you out with the streaming (which is definitely the best way forward)

  • dammit! Does it has to come from A4/A5? That's where the display is hooked up. Lots of other peripherals on the other pins too.

    The code is less than 400 lines, around 8k


    1 Attachment

    • IMG_20161003_134302.jpg
  • Wow, that all looks really compact!

    Well, as above, you can use PWM (the Pico board doesn't even have a DAC). Adding a resistor+capacitor could smooth the signal out quite nicely, although I've tended to feed it straight into piezo transducers without much of an issue. I imagine that'll be good enough for a lot of things, but you're stuck with A4 or A5 for the DAC I'm afraid. If you hadn't seen it, http://www.espruino.com/EspruinoBoard#pinout provides a neat diagram of what is where.

    With a bit of fiddling you could probably remove just that pin and wire to another place - either just ship it in half and remove each half, or if you suck the solder off one side you could get some pliers on it, and then a hot soldering iron on the other might be enough to melt everything and let you get the pin out.

  • cheers G, I'll give it a go....

  • OK, so moved the pin and can hear a partial sound played.. (progress?).

    However, I can't get the whole file playing. If I set repeat:true then I can, but it's like an echo!

    function playSoundFile()
    {
    var f = E.openFile("/audio/1.raw","r");

    var w = new Waveform(2048, {doubleBuffer:true});
    // load first bits of sound file
    w.buffer.set(f.read(w.buffer.length));
    w.buffer2.set(f.read(w.buffer.length));
    var fileBuf = f.read(w.buffer.length);
    // when one buffer finishes playing, load the next one
    w.on("buffer", function(buf) {
    buf.set(fileBuf);
    fileBuf = f.read(buf.length);
    if (fileBuf===undefined) w.stop(); // end of file
    });
    // start output
    analogWrite(A4, 0.5);
    w.startOutput(A4,30000,{repeat:false});
    }

    1.raw attached...

    Struggling with this simple thing!!!!!


    1 Attachment

  • Wow, playing at 30,000's not going to work. The page says right at the top:

    Waveforms can use up so much CPU that they make render Espruino unresponsive if you create a repeating Waveform with a frequency that is too high (above 10kHz input or 20kHz output).

    Did you try literally just using the example as-is first? :)

  • ummmm, may have :)

    Actually I have tried at lower 4000 as the raw was encoded.

  • Ok, so I get a different result when playing your file using the example code. It still doesn't sound right, but that could be because you saved as signed RAW rather than unsigned?

  • Oh really, I did follow the instructions, or so I though, I'll try saving the file again.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Adafruit VS1053 Codec + MicroSD Breakout - MP3/WAV/MIDI/OGG Play + Record - v4

Posted by Avatar for davenelson @davenelson

Actions