• So far the Arduino code for the LSM9DS1 has been ported to Espruino, but to make it really useful it should be worked into module form.
    There are a lot of knobs on the virtual control panel for this chip. In the previous version any changes to the knobs needed to be edited in the LSM9DS1.prototype.init function.
    Today the code is modified so that the knobs are initialized to default values and an optional set of options can be supplied to the LSM9DS1.prototype.init function.
    This is accomplished by changing the init function to the following

    LSM9DS1.prototype.init=function(options)­{
      var i,j;
      for (i=0; i<3; i++){
      this.gBias[i] = 0;
      this.aBias[i] = 0;
      this.mBias[i] = 0;
      this.gBiasRaw[i] = 0;
      this.aBiasRaw[i] = 0;
      this.mBiasRaw[i] = 0;
     }
    //process and changes from options
    if(typeof options === "undefined" )
      console.log("options undefined");
    if(typeof options !== "undefined"){
      console.log("options defined");
     for(i in options){
    //console.log(options);
      if(options.hasOwnProperty(i)){
      for(j in this){//LSM9DS1){
    //     console.log(i,j);//,options[i],LSM9DS1[j­]);
       if(j==i){
         console.log(i,j,options[i],this[j]);
         this[j]=options[i];
       }
      }
     }
    }
    }
    };
    

    The optional options are outlined in the attached file options.js.
    For example to change the acceleration sample rate from 6 to 5 :

    	// accel sample rate can be 1-6
    	// 1 = 10 Hz    4 = 238 Hz
    	// 2 = 50 Hz    5 = 476 Hz
    	// 3 = 119 Hz   6 = 952 Hz
    	accel_sampleRate: 6,
    

    The code that calls the init function uses an option object containing only the options we wish to change.

    function start(){
    I2C3.setup({ scl :A8, sda: B4} );
    var W=new LSM9DS1(I2C3);
    
    var myoptions={ //make changes to basic configuration here
      xgAddress: 0x6B,
      mAddress: 0x1e,
      test: 1,
      accel_sampleRate: 5,
    };
    
    W.init(myoptions);
    //W.init();
    console.log(W.begin());
    var nn=setInterval(function () {
        readall(W);
    }, 200);
    }
    

    The output of the substitutions made in the init function:

    >options defined
    xgAddress xgAddress 107 107
    mAddress mAddress 30 30
    test test 1 0
    accel_sampleRate accel_sampleRate 5 6
    

    2 Attachments

About