pico standalone SD card GPS

Posted on
  • Hi - trying to solve an issue using an espruino pico and an sd card loggin gps and other sensor data

    when connected to the usb and the ide it functions fine and logs the data as csv but as soon as i go to standalone mode using a battery nothing seems to happen

    i have placed it all in onInit but can't seem to get anything going

    any help would be super appreciated as i am super up against a project deadline on this thanks

    function oninit(){
    // 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, B1 /*CS*/);
    // see what's on the device
    //console.log(require("fs").readdirSync(­));
      Serial1.setup(9600,{tx:B6,rx:B7});
     require("fs").appendFileSync("data2.csv"­ , "new");
    var gps = require("GPS").connect(Serial1, function(data) {
    SPI1.setup({mosi:B5, miso:B4, sck:B3});  
    E.connectSDCard(SPI1, B1 /*CS*/);
      
    //var fs = E.openFile("data2.csv","w");
      i++;
     var readings = [
        analogRead(A0),
        analogRead(A1),
        analogRead(A2),
       data.lat,
       data.lon,
       data.time
      ];
     //f.write(readings.join(", ")+"\n");  
      ar=analogRead(A2);
      //console.log(readings);
      require("fs").appendFileSync("data2.csv"­ , readings.join(", ")+"\n");
     // f.close();
    });
    
    setInterval(gps, 1000);
    
      
    }
    function gps(){
    
    var fs;
    var i=0;
    var gps = require("GPS").connect(Serial1, function(data) {
    SPI1.setup({mosi:B5, miso:B4, sck:B3});  
    E.connectSDCard(SPI1, B1 /*CS*/);
      
    //var fs = E.openFile("data2.csv","w");
      i++;
     var readings = [
        analogRead(A0),
        analogRead(A1),
        analogRead(A2),
       data.lat,
       data.lon,
       data.time
      ];
     //f.write(readings.join(", ")+"\n");  
      ar=analogRead(A2);
      //console.log(readings);
      require("fs").appendFileSync("data2.csv"­ , readings.join(", ")+"\n");
     // f.close();
    });
    
    }
    oninit(); 
    save();
    
  • Hi - The issue is just that the 'console' reverts to Serial1 (which you have the GPS on when USB is disconnected).

    Just add USB.setConsole(1) to onInit() and you'll be sorted - it forces the console to stay on USB.

    Also, I would:

    • Rename oninit to onInit (it's case sensitive)
    • Remove the call to oninit() and save() from your code, and just type save() on the left-hand side after upload.

    That'll make sure onInit() is called just once on startup (it's done automatically after the save()). If it gets called twice (once before save and once after) then you'll end up with 2 sets of GPS modules added and so two sets of identical readings added to the file.

    Hope that helps!

  • Gordon that's amazing!

    thank you all up and running now - coming from using arduinos i'm still getting my head around the espruino workflow

    thanks

    b

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

pico standalone SD card GPS

Posted by Avatar for user73554 @user73554

Actions