You are reading a single comment by @christian-nils and its replies. Click here to read the full conversation.
  • Hello,

    I would like to log some IMU data using my Puck.js v.2.

    I have set up a SD card reader (w/ SPI HW set to 8Mbps) on it so I can log the data. I can log the data at maximum 160Hz in average which is quite low for what I would like to do. I guess there are a lot of "wasted" time when converting the JSON object to string, and then when writing the data to the file. Note, I am using "Stream File IO".

    I am far from being an expert, but maybe some on this forum could help me to know how much I can expect from the device. If I were to write my own C code to log the data from the IMU directly to the SD card, what would be the possible maximum sampling rate for instance?

    (My messy code below)

    function onInit(){
      // Wire up up MOSI, MISO, SCK and CS pins (along with 3.3v and GND)
    SPI1.setup({mosi:D30, miso:D28, sck:D29, baud: 8000000});
    // console.log(E);
    E.connectSDCard(SPI1, D31 /*CS*/);
    // see what's on the device
      try {
        console.log(require("fs").readdirSync());
      } catch(error){
        console.log(error);
      }
    }
    
    var data = [];
    var i = 0;
    // Store data into filesystem
    function storeMyData(fID, start, a) {  
      if (i>100) {
        i = 0;
        var t = new Date.now();
        fID.write(data);
        console.log((new Date.now()) - t);
        data = [];
      } else {
        data += (Date.now()-start) + "," + 
                a.acc.x + "," +
                a.acc.y + "," +
                a.acc.z + "," +
                a.gyro.x + "," +
                a.gyro.y + "," +
                a.gyro.z + "\n"; 
      } 
      i++;
    }
    
    function openFile(){
      var start = Date.now();
      var fID = E.openFile("data"+start+".csv", "w");
      fID.write("Time (ms), "+
                "acc X, "+
                "acc Y, "+
                "acc Z, "+
                "gyro X, "+
                "gyro Y, "+
                "gyro Z \n");
      return {fID: fID, start: start};
    }
    
    onInit();
    var res = openFile();
    var fID = res.fID;
    const start = res.start;
    
    function onButton(e){
      d = e.time - e.lastTime;
      if (d>0.5) {
        digitalPulse(LED2, 1, [100, 100, 100]);
        Puck.accelOn(208);
        Puck.on('accel', function(a) {
          storeMyData(fID, start, a);      
        });
      } else {    
        try {
          Puck.accelOff();
          fID.close();
          console.log("stopped!");
          digitalPulse(LED1, 1, [100, 100, 100]);
        } catch(error) {
          console.log(error);
        }    
      }
    }
    

    Thanks in advance,

    Greetings

About