Binaries with "fs" SD card support NEEDED!!!

Posted on
Page
of 2
/ 2
Next
  • I am desperately looking for help!

    I just started using Espruino on the ESP8266 modules. Everything went as smooth as butter, but i keep getting error messages like "module "fs" not found.

    After searching on the internet i found a post that said, that there is a possibility that these libraries are not available in the esp8266-espruino binaries and that you have to build/compile them yourself with the needed libraries.

    That post was 1 year old and i wondered if this is still the case, and if someone has binaries that allready contain SD/uSD support.

    Thanks in advance!

  • If I recall there was one line change required to get this to compile. You could try @jumjum online firmware builder, and turn on the fs module in the compile.

  • Thank you for your reply,

    I have looked but i don"t see the "fs" module there. Is it maybe named differently?

    Also you can add extensions to the firmware, but where would i find those?

  • Module fs depends on module E (for SD card management). The physical SD card has to be connected by ie SPI.
    I don't know what you are doing exactly, but there is the module File for streaming from and to files, too.
    Perhaps http://www.espruino.com/File+IO#line=19,­25 helps.

  • @ManoBiletsky
    The zip file contains espruino_esp8266_user1.bin and espruino_esp8266_user2.bin

    To compile:

    export USE_FILESYSTEM=1
    and I commented out USE_GRAPHICS in the Makefile as there is not enough space for both.

    This change is also needed as the macro fails:

    void jswrap_file_skip_or_seek(JsVar* parent, int nBytes, bool is_skip) {
      if (nBytes<0) {
        //jsWarn(is_skip ? "Bytes to skip must be >=0" : "Position to seek to must be >=0");
        if ( is_skip) jsWarn("Bytes to skip must be >=0");
        if ( is_skip <= 0 ) jsWarn( "Position to seek to must be >=0");
        return;
      }
    

    I've not tested with an SD card - however the modules loads!

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v86.113 Copyright 2016 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 4MB:512/512, manuf 0xe0 chip 0x4016
    
    >fs=require('fs');
    =function () { [native code] }
    

    1 Attachment

  • Thank you so much! I will test it today.

  • a couple of questions:

    I upload the binaries with esptool?
    To which memory block?
    and the code adjusments i have to make in my code in the espruino IDE?

  • @ManoBiletsky

    Yes upload the .bin files with esptool - like you did for the initial firmware.

    The block depends on which esp8266 board you have - just do what you did last time...

    As far as code changes - you will need to initialize the spi to however you have wired up the sd card.

  • Ah i see. i will give it a try. and i'll post my results here.

    Thanks again

  • Next problem.... with my initial upload i followed a tutorial on the espruino main site.

    There it said to flash using this line;

    $ /path/to/esptool/esptool.py --port /dev/ttyUSB0 --baud 115200 \
      write_flash --flash_freq 40m --flash_mode qio --flash_size 8m \
      0x0000 "boot_v1.85.bin" 0x1000 espruino_esp8266_user1.bin \
      0x7C000 esp_init_data_default.bin 0x7E000 blank.bin
    

    however there is no user2.bin in this line. So how do i figure out what location i must flash it to?

  • Just flash the user1. User2 is used for ota(over the air) updates.
    This is done using the wiflash.sh script.

  • hahaha, i just figured it out 30 seconds ago. Thanks anyway.

    when i try to compile/send .js script, i still get the fs library not found error.
    though i havent yet implemented the piece of code you wrote above.

  • The code posted above was changed needed in the c code to compile... Not related

    If you see v186.113 then you have the updated firmware.

    Ignore the warning about the missing module - it is because the normal esp8266 does not have the module and the web Ide doesn't know it is available.

    On the right hand side of the ide try:

    
    >fs=require('fs');
    =function () { [native code] }
    

    You should see the 2nd line if the module loaded rather than undefined

  • Indeed! it works.

    SD card not running yet. still figuring out what code to use. Ill keep you posted! thanks again!

  • this is my code:

    function onPageRequest(req, res) { 
      var a = url.parse(req.url, true);
      if (a.pathname.substr(-1)=="/") { // a slash at the end, list the directory
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write("<html><body><p>Contents of "+a.pathname+"</p><ul>");
          res.write('<li><a href="'+a.pathname+f+'">'+f+'</a></li>')­;
    
        res.end("</ul></body></html>");
      } else { // No slash, try and open file
        f = E.openFile(a.pathname, "r");
        if (f !== undefined) { // File open succeeded - send it!
          res.writeHead(200, {'Content-Type': 'text/plain'});
          f.pipe(res); // streams the file to the HTTP response
        } else { // couldn't open file
          // first check if this was a directory             
          if (("E").readdir()!==undefined) { 
            // it was a directory - forward us to a page with the '/' on the end
            res.writeHead(301, {'Location': a.pathname+"/", 'Content-Type': 'text/plain'});  
            res.end("Moved");                                
          } else {                                              
            // else not found - send a 404 message
            res.writeHead(404, {'Content-Type': 'text/plain'});
            res.end("404: Page "+a.pathname+" not found");
          }
        }
      }
    }
    
    var wlan;
    var f;
    function onInit() {
      // Wire up up MOSI, MISO, SCK and CS pins (along with 3.3v and GND)
      SPI1.setup({mosi:D12, miso:D13, sck:D14});
      E.connectSDCard(SPI1, D4);
      // see what's on the device
      console.log(require("fs").readdirSync())­;
      var wifi = require("Wifi");
    
      wifi.connect("My_SSID", {password: "My_password"});
      require("http").createServer(onPageReque­st).listen(80);
    }
    onInit();
    

    but the output i am getting from the terminal window:

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v86.113 Copyright 2016 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 1MB:512/512, manuf 0xe0 chip 0x4014
    >echo(0);
    ERROR: Unable to mount SD card : NOT_READY
    undefined
    =undefined
    > 
    
  • If you get ERROR: Unable to mount SD card : NOT_READY that'll some kind of wiring problem with the SD card. First I'd try just setting up the SD card and reading a file to make sure you have that part working ok.

  • Have a look here:
    http://forum.espruino.com/conversations/­285779/#comment13002694
    There might be some clues on how to setup your wiring..

    The Nodemcu:D4 type set up may help instead of just using D4 if you are going by the labels on the board...

  • I tried changing the pin designation, but i get no change at all.

    When i change the CS pin to pin 5 i get no "sd card" error except 'connection lost' in the terminal window.

    i tried every possible pin combination. with and without the Nodemcu.D..

    my wiring is correct because i have used the sd card in the arduino IDE and that works just fine.

  • You could try software SPI:

    var s = new SPI();
    s.setup({mosi:D12, miso:D13, sck:D14});
    E.connectSDCard(s, D4);
    

    You'd have to play with the pins too.

    Note that it's NodeMCU.D1/etc not Nodemcu.D1/etc.

  • using this:

    function onInit() {
      var s = new SPI();
      E.connectSDCard(s, NodeMCU.D4);
      s.setup({mosi:NodeMCU.D13, miso:NodeMCU.D12, sck:NodeMCU.D14});
      // see what's on the device
      console.log(require("fs").readdirSync())­;
    }
    
    onInit();
    

    i still get the same output:

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v86.113 Copyright 2016 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 1MB:512/512, manuf 0xe0 chip 0x4014
    >echo(0);
    ERROR: Unable to mount SD card : NOT_READY
    undefined
    =undefined
    > 
    
  • Why did you swap the order of the lines around? Try:

      var s = new SPI();
      s.setup({mosi:NodeMCU.D13, miso:NodeMCU.D12, sck:NodeMCU.D14});
      E.connectSDCard(s, NodeMCU.D4);
    

    it might help...

  • I allready tried that first. And i tried again to be shure just now.
    in the first section i did only your code from the last post, and the second i added one line to call for the FS library. Both didn't work... :(

    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v86.113 Copyright 2016 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 1MB:512/512, manuf 0xe0 chip 0x4014
    >echo(0);
    =undefined
    >reset();
    =undefined
    
    
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v86.113 Copyright 2016 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 1MB:512/512, manuf 0xe0 chip 0x4014
    >echo(0);
    ERROR: Unable to mount SD card : NOT_READY
    undefined
    =undefined
    > 
    
  • I think you need to simplify here.

    Forgot about the oninit() and wifi stuff.

    You want to get the simple case of the spi and init of the sd card sorted.

  • I also notice you swapped the SPI pins around at some point:

    SPI1.setup({mosi:D12, miso:D13, sck:D14});
    s.setup({mosi:NodeMCU.D13, miso:NodeMCU.D12, sck:NodeMCU.D14});
    
  • I also tried to get sdcard running with ESP8266.
    First problem was naming of pins in Espruino and naming on boards.
    Figured out at the end that
    NodeMCU.D1 is D5
    NodeMCU.D2 is D4
    NodeMCU.D3 is D0
    NodeMCU.D4 is D2
    NodeMCU.D5 is D14
    NodeMCU.D6 is D12
    NodeMCU.D7 is D13
    NodeMCU.D8 is D15
    NodeMCU.D9 is D3
    NodeMCU.D10 is D1
    Based on this connected D12 to mosi,D13 to miso and D14 to sck
    cs of SDCard was connected to B15
    Script now looked like this

    var s = new SPI();
    s.setup({mosi:NodeMCU.D7,miso:NodeMCU.D6­,sck:NodeMCU.D5});
    E.connectSDCard(s,NodeMCU.D8
    fs = require("fs");
    fs.readdir();
    

    Running this I got a reset about 2 secs later.
    To get some more information, switched ESP8266Log to serial0

    var e = require("ESP8266");
    e.setLog(2);
    

    Running script above again error log and stackdump was sent to my terminal. This included information about the location where error occured.
    First of all, there was an Fatal exception 9.
    By comparing pc with listing, exception happened in check_fs (file ff.c)
    Thats a part of reading boot sector on SDCard.
    This point marked the end of my knowledge :-(

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

Binaries with "fs" SD card support NEEDED!!!

Posted by Avatar for ManoBiletsky @ManoBiletsky

Actions