• Testing the LSM9DS1 Module

    Note that the module is still under construction at this point.

    Setup a project in WebIDE

    WebIDE will use a projects folder with the LSM9DS1.js placed in the Modules sub-folder.
    In WebIDE click on the gear icon in the upper right corner and then click on Project. You can then create a project if you haven’t done so already. When you “require” a module, the project module subfolder is part of the search chain.

    Magtest.js

    //Magtest.js 30Apr2017
    ////////////////////////////////////
    function testMag(){
    var temp;
    var i;
    W.Mwrite(W.MREGval.TEMP_COMP,1);
    /* ON OMZ
    0 = Low-power mode
    1 = Medium-performance mode
    2 = High-performance mode
    3 = Ultra-high performance
    */
    W.Mwrite(W.MREGval.OM,3);
    W.Mwrite(W.MREGval.OMZ,3);
    /* DO
    0 =  0.625 Hz.
    1= 1.25
    2 = 2.5
    3 = 5
    4 = 10
    5 = 20
    6 = 40
    7 = 80
    */
    W.Mwrite(W.MREGval.DO,3);//5 Hz
    //W.Mwrite(W.MREGval.DO,7);//80 Hz
    W.Mwrite(W.MREGval.FAST_ODR,0);
    W.Mwrite(W.MREGval.ST,0);
    /* FS
    Full scale
    0 = ± 4 gauss
    1 = ± 8 gauss
    2 = ± 12 gauss
    3 = ± 16 gauss
    */
    W.Mwrite(W.MREGval.FS,1);
    W.Mwrite(W.MREGval.MD,0);//continuous convert
    //W.Mwrite(W.MREGval.MD,1);//single convert
    W.Mwrite(W.MREGval.BLE,0);//Endian of data
    //W.Mwrite(W.MREGval.BDU,0);//continuous­ update
    W.Mwrite(W.MREGval.BDU,1);//block update
    W.Mwrite(W.MREGval.FAST_READ,0);
    }//end testMag
    
    function displayMag(){
    var m;
    if(W.Mread(W.MREGval.ZYXDA)){  //new data available
    // console.log("Mag data available");
     m=W.mReadBytes(W.MagRegs.OUT_X_L_M, 6);
     console.log(" "+m[0]+","+m[1]+","+m[2]);
    }//endif
    }//end displayMag
    
    
    //Configuration
    //The I2C pins that the LSM9D01 is connected to
    //PICO I2C pins
    //IC1  sda=B7  scl=B6
    //IC1  sda=B9  scl=B8  shim pins
    //IC3  sda=B4  scl=A8
    //IC2  sda=B3  scl=B10
    var W;
    function start(){
    //  console.log("start");
     I2C3.setup({ scl :A8, sda: B4} );
    //console.log(I2C3);
     var xgAddress= 0x6B;// Would be 0x1C if SDO_M is LOW
     var mAddress= 0x1e;// Would be 0x6A if SDO_AG is LOW 
     W=require("LSM9DS1").connect(I2C3,xgAddr­ess,mAddress);
    // W=new LSM9DS1(I2C3,xgAddress,mAddress);
     W.run();//Get it started
     W.showAG();
     W.showMag();
     testMag();
     setInterval(function () {
      displayMag();
     }, 200);
    }//end start
    
    //function startPgm(){
    //Wait for program to load
    setTimeout(function () {
     start();
    }, 1000);
    //}//end startPgm
    

    Some raw output of the magnetometer, X, Y, and Zaxis

    ( note units are raw counts and no zero offset has been applied )

    700,-950,-802
     678,-944,-802
     703,-947,-806
     700,-936,-825
     678,-945,-807
     677,-948,-830
     675,-938,-826
     686,-944,-830
     685,-964,-831
     686,-949,-838
     695,-938,-848
     672,-975,-855
     684,-960,-827
     679,-962,-841
     680,-968,-845
     672,-943,-846
    >clearInterval();
    =undefined
    > 
    

    The module needs code to read the accelerometer and gyro data.


    2 Attachments

About