Espruino Pico and SD cards

Posted on
Page
of 2
/ 2
Next
  • Does this work?

    I haven't tried it, but I just noticed that E.openFile was undefined there - which is not a good sign. Is SD card support not being built into the Pico?

  • I think you need to compile the firmware for it yourself, as filesystem isn't defined in the makefile for the pico. See this thread: http://forum.espruino.com/conversations/252934/

  • That thread is from before Gordon made it so you can have the filesystem on other pins though. With FS possible on pins specified at runtime, the Pico ought to have this compiled in, I reckon.

    Does anything other than USE_FILESYSTEM=1 need to be specified to build pico firmware with filesystem support?

  • Yeah, it would be a good one to compile in by default, if there's space for it. (Or maybe a candidate for implementing as an installable module, like the new ESP8266 module... but I suspect that's no easy task)

    I tried the sd card functions on my Nucleo board yesterday and they were undefined. If I get a chance I'll try compiling firmware for it with USE_FILESYSTEM=1 and give it a go, I've got an sd module I've been meaning to try out...

  • Does anything other than USE_FILESYSTEM=1 need to be specified to build pico firmware with filesystem support?

    Shouldn't be - that's my fault... It has been done and tested on the Pico - I don't know how it got left out. I'll make sure it's in the new release.

  • E.connectSDCard is also undefined on my Pico :(

    What exactly do I have to do in order to make an external SD card breakout board work with the Pico? Re-compiling the firmware sounds messy, but if there were a step-by-step instruction, I would dare.

  • Have you updated firmware since you got the board?

    E.connectSDCard() has been in the firmware for over a month.

  • @Dennis, as @DrAzzy said, try updating the firmware on your Pico - there are some instructions on the Quick Start page, under 'Software Updates'.

  • Ah okay, I will do that. Thanks! With the original Espruino board, the IDE always showed the little exclamation mark on the top right when a new firmware was available. Since this icon doesn't appear when I'm connected to the Pico, I assumed that the Pico already has the latest firmware installed.

  • Ahh, yes, it's something I've fixed and which I'll put in the next release of the IDE :)

  • So is there an example and tutorial available to connect an sd card to the Pico? Maybe a recommended breakout board?

  • small example with SD card module connected to SPI1

    function onInit() {  
      // initial SPI1 for SDCard module
      SPI1.setup({sck:A5, miso:A6, mosi:A7 });
      E.connectSDCard(SPI1,B1/*CS*/);
      console.log(require("fs").readdirSync());
      require("fs").writeFileSync("hello.txt", "Hello World");
      console.log(require("fs").readFileSync("hello.txt")); // prints "Hello World"
      require("fs").appendFileSync("hello.txt", "!!!");
      console.log(require("fs").readFileSync("hello.txt")); // prints "Hello World!!!"
    }
    
    // call onInit() if it is first start
    onInit();
    
    
  • Thank you Jorgen!

  • An suggestions for which SD card module would be easy to integrate? Or would anything go?

  • Just about any will work - they're like $1-3 shipped from china. You can even just solder wires onto a microSD to SD converter and connect directly... :-P

  • Just done exactly that... having broken the SD breakout board :(


    1 Attachment

    • 2015-08-16 13.16.19.jpg
  • Here's a ref image I jotted down to for my own use, hopefully it's helpful to someone in the future.


    1 Attachment

    • ref.jpg
  • Thanks! Actually it'd probably be worth us having an SD card page on the website at some point? There's very little info on it at the moment.

  • Hi there !

    About the SD Card page, I can write one / some of its content if you wish ;p
    -> I built 2 adapters & wired one to a Pico, maybe the pics I took while doing so may be useful to some users ( as did the pics above for me ;) )

    Moreover, I have a little question regarding the SDCard waveform stream:
    I may be doing something "wrong" ( aka wiring stuff directly, without no resistor nor cap ), but it seems whatever the raw audio file I try, with whatever sample rate, I just can't play correct audio on the Pico from the SD ( even with files tinier than 8kB, ex 4kB ).

    Beeping/buzzing is fine, but I intended to play PCM audio so .. not exactly right for my usage ..

    thu, does anyone have a repo where I could find some samples that are working on the Pico ?
    Nb: I didn't try ( yet ) to convert some to strings using the converter page ( .. ), but it'd be way more cumbersome than just loading these off the SD ..

    Looking forward to reading from you on this, keep up the good work ++


    4 Attachments

    • SDCard_annotated.JPG
    • SDCard_Pico2.JPG
    • SDCard_Pico3.JPG
    • SDCard_Pico.JPG
  • Hi! Thanks for the report of the issue on the File page.

    Some more info on the SD card would be really cool - the first image you posted is really helpful!

    What happens with the waveform code? Does it just 'not work', or does the playback have gaps in it?

  • Haha, you up :)

    -> for the File page, as usual, "if I can figure stuff out/help, .." ;P

    -> for the SD card pic(s): I quickly posted the annotated one, in case someone stumble upon this post, but I'm willing to do it under illustrator, for a nicer rendering, as well as add annotation on the Pico pic as well, and also add the corresponding example code / pinout diagram
    => I guess I'll make such "page" with a github README.md & then post you the url for approval / fork to the Espruino repo, what'd be the easier for you ?

    -> concerning the Waveform code ( posted below ), I can record what's happening: I get a beep out ( as when using only "analogWrite(BUZZER, 0.5)" ) + some "noise" ( which seems close to what I get when specifying wrong sample rate while opening a file in Audacity )
    => as far as I can tell, it seems that whatever smaple rate is chosen / whatever the file, I get the above results :/

    /* works fine */
    // debug test the buzzer
    var BUZZER=B3;
    analogWrite(BUZZER, 0.5); // simplest bip
    analogWrite(BUZZER, 0.5, { freq: 1000 } ); // bip with freq ctrl ( here 1kHz )
    digitalWrite(BUZZER,0);  // stop the bip
    
    /* does NOT work as expected */
    // output a 4kHz 8 bit unsigned sound file loaded from the SD card:
    var PICOSPK=B4;
    var wave = require("fs").readFile("G01.raw");
    var w = new Waveform(wave.length);
    w.buffer.set(wave);
    
    analogWrite(PICOSPK, 0.5); 
    w.startOutput(PICOSPK,15625);
    
    
    
    /* does NOT work as expected either */
    var f = E.openFile("G01.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
    });
    
    analogWrite(PICOSPK, 0.5);
    w.startOutput(PICOSPK,15625,{repeat:true});
    //w.startOutput(PICOSPK,4000,{repeat:true});
    

    -> I'm about to record the output of the 8 ohms 0.25W speaker connected directly to B4, I'll post that right below
    -> for the said-samples, I attached few ( none seems to work for me, even though I encoded some myself using Audacity as exposed)

  • sample rate 4000


    1 Attachment

  • sample rate 15625


    1 Attachment

  • original sample ( not encoded myself using Audacity )


    1 Attachment

  • Have you tried:

    analogWrite(BUZZER, 0.5, { freq: 40000 } );
    

    That'll do PWM on the speaker, but at a frequency above your hearing threshold. You should then be able to hear the actual sound and not the beep?


    But as far as docs, maybe you could do something on Frtzing (if there's an SD card part? It could be easier). I guess just adding to the existing File IO page might be fine?

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

Espruino Pico and SD cards

Posted by Avatar for DrAzzy @DrAzzy

Actions