• Calibrating the Accelerometer

    The procedure is similar to the magnetometer calibration but several things are done differently.

    1. There are 3 axis, and if the accelerometer is attached to one face of a cube, we need to collect data with each of the six faces of the cube on the bottom. Data taken when the sensor is in motion may contain additional acceleration values that would distort the calibration.
    2. The magnetometer used the average R value, for the accelerometer we will calculate the counts needed to produce a 1G value, taking the range setting of the accelerometer as a factor.

      We need a way to signal the program that the sensor is positioned and ready to acquire some data.

      With WebIDE this can be achieved by reassigning the console with the setConsole() function.
      With a PICO this has its perils if you set the program up to run on boot and save the program.
      You need to provide a way to get the console back to the USB port. Preferably several ways!

      //ConsoleMenu.js 11 May 2017
      
      //How not to brick a PICO when reassigning the console
      // away from the USB port to do menu programs
      //Setup the button to light the LED and reset the Pico
      //Always include this code when a save() and oninit() functions are // used.
      setWatch(function(e) {
      digitalWrite(LED1, e.state);
      USB.setConsole();
      reset();
      }, BTN, { repeat: true });
      
      E.on('init', function() {
      console.log("Hello");
      startPgm();
      });
      //input cmd from terminal,send it to parsecmd()
      var sst=""; //The input buffer
      USB.on('data', function (data) {
      var i;
      sst+=data;
      // look for control c in input stream
      if(sst.indexOf(String.fromCharCode(3))>-­1){
      USB.setConsole();
      reset();
      }//   console.log("control C seen");
      USB.print(data);
      if(sst.length>-1)
      if(sst.charAt(sst.length-1)==="\r")selec­tparser();
      });
      
      //Espruino replies here
      LoopbackA.on('data',function(data){
      USB.print(data); //sending data to terminal
      });
      console.log("In left pane type startPgm();");
      console.log("Use startPgm() first and make sure you can exit back to the console");
      console.log("Once you are sure that a proper exit works then type  save();");
      
      var menulevel=0;
      function startPgm(){
      setTimeout(function () {
      // start();
      LoopbackB.setConsole();
      mainmenu();
      }, 1000);
      }//end startPgm
      
      function mainmenu(){
      USB.print("\n\rMain Menu\n\rType somthing or a control C to Exit\n\r");
      //    USB.setConsole();
      }//end mainmenu
      
      function selectparser(){
      USB.print("\n\r"+sst+"\n\r");
      //    USB.setConsole();
        
      }//end select parser
      

    The attached file CollectAGdata.js combines the above menu program with AGtest1.js to produce a program that collects 32 samples and wait for a carriage return. The sensor can be repositioned and the next setting can be collected by pressing return. When finished type any character followed by a return to exit the program. The data are then copied from the WebIDE left pane and pasted nto a .CSV file. Some example output:

    G=, -716,194,-17, A=, -148,-780,16899
    G=, -711,193,-18, A=, -154,-787,16901
    G=, -718,190,-18, A=, -156,-781,16944
    G=, -719,193,-14, A=, -169,-762,16929
    G=, -714,194,-12, A=, -178,-765,16942
    G=, -714,194,-18, A=, -186,-730,16940
    G=, -716,190,-17, A=, -195,-737,16940
    G=, -725,191,-17, A=, -210,-736,16887
    G=, -711,187,-15, A=, -182,-746,16924
    G=, -713,190,-19, A=, -225,-741,16894
    G=, -712,192,-21, A=, -209,-760,16893
    G=, -704,194,-12, A=, -197,-743,16876
    G=, -719,198,-15, A=, -132,-754,16905
    G=, -717,217,-15, A=, -145,-706,16794
    G=, -713,184,-15, A=, -207,-902,16881
    G=, -718,204,-25, A=, -185,-817,16879
    G=, -722,193,-9, A=, -110,-743,16895
    G=, -721,196,-28, A=, -244,-878,16873
    G=, -735,190,-14, A=, -189,-795,16896
    G=, -720,214,-21, A=, -179,-749,16898
    G=, -714,176,-18, A=, -219,-867,16894
    G=, -726,199,-26, A=, -142,-731,16935
    G=, -730,190,-18, A=, -156,-772,16936
    G=, -719,190,-26, A=, -196,-758,16898
    G=, -714,188,-20, A=, -129,-745,16981
    G=, -719,193,-26, A=, -203,-777,16936
    G=, -726,182,-19, A=, -210,-741,16947
    G=, -723,199,-24, A=, -232,-722,16910
    G=, -735,187,-27, A=, -149,-738,16921
    G=, -729,188,-30, A=, -231,-760,16885
    G=, -723,190,-23, A=, -167,-756,16869
    G=, -715,192,-21, A=, -221,-760,17003
    <- LoopbackB
    -> USB
    

    The data are then pasted in a spreadsheet similar to the one used for the magnetometer and the twelve calibration values are calculated.


    2 Attachments

About