• TestLSM9DS1.js
    21 Nov 2016
    Using a Pico 1v88

    I’m starting work on an I2C driver for the Sparkfun 9DoF Sensor Stick
    https://www.sparkfun.com/products/13944
    3-axis Magnetometer, Gyro and Accelerometer.
    As a starting point I’ve downloaded the Arduino Library from
    https://github.com/sparkfun/SparkFun_LSM­9DS1_Arduino_Library
    The board is scheduled to arrive tomorrow. The attached Espruino code has been derived from the Arduino library. TestLSM9DS1.js
    A few functions related to the I2C have been stubbed until the board arrives and testing can begin. Additional functions beyond the basics have yet to be added.
    Any suggestions on writing the stubbed I2C functions are welcome.

    TestLSM9DS1.js
    21 Nov 2016
    */
    ……
    LSM9DS1.prototype.mReadByte=function(sub­Address){
    //uint8_t LSM9DS1::mReadByte(uint8_t subAddress)
    //		return I2CreadByte(_mAddress, subAddress);
      console.log("mReadByte ",_mAddress, subAddress);
      return 0;
    };
    
    LSM9DS1.prototype.xgReadByte=function(su­bAddress){
    //uint8_t LSM9DS1::xgReadByte(uint8_t subAddress)
     //return I2CreadByte(_xgAddress, subAddress);
      console.log("xgReadByte ",_xgAddress, subAddress);
    return 0;
    };
    …..
    LSM9DS1.prototype.xgWriteByte=function(s­ubAddress,data){
    //void LSM9DS1::xgWriteByte(uint8_t subAddress, uint8_t data)
    ////I2CwriteByte(_xgAddress, subAddress, data);
      console.log("xgWriteByte ",_xgAddress, subAddress, data);
    };
    ……
    LSM9DS1.prototype.mWriteByte=function(su­bAddress,data){
    ////		return I2CwriteByte(_mAddress, subAddress, data);
      console.log("mWriteByte ",_mAddress, subAddress, data);
      return 0;
    };
    …..
    LSM9DS1.prototype.xgReadBytes=function(s­ubAddress,dest,count){
    //void LSM9DS1::xgReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count){
    ////	I2CreadBytes(_xgAddress, subAddress, dest, count);
      console.log("xgReadByte ",_xgAddress, subAddress, dest, count);
    };
    …..
    LSM9DS1.prototype.readMag=function(){
    //void LSM9DS1::readMag(){
    	var temp=Uint8Array(6); // We'll read six bytes from the mag into temp	
    	this.mReadBytes(Mags.OUT_X_L_M, temp, 6); // Read 6 bytes, beginning at OUT_X_L_M
     this.mx = (temp[1] << 8) | temp[0]; // Store x-axis values into mx
     this.my = (temp[3] << 8) | temp[2]; // Store y-axis values into my
     this.mz = (temp[5] << 8) | temp[4]; // Store z-axis values into mz
    };
    
    LSM9DS1.prototype.mReadBytes=function(su­bAddress,dest,count){
    //void LSM9DS1::mReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count){
     ////I2CreadBytes(_mAddress, subAddress, dest, count);
      console.log("mReadBytes ",_mAddress, subAddress, dest, count);
    };
    

    The current output of the stubbed code:

    >15
    mReadByte  30 15
    xgReadByte  107 15
    xgWriteByte  107 16 192
    xgWriteByte  107 17 0
    xgWriteByte  107 18 0
    xgWriteByte  107 30 58
    xgWriteByte  107 19 0
    xgWriteByte  107 31 56
    xgWriteByte  107 32 192
    xgWriteByte  107 33 0
    mWriteByte  30 32 28
    mWriteByte  30 33 0
    mWriteByte  30 34 0
    mWriteByte  30 35 12
    mWriteByte  30 36 0
    0
    xgReadByte  107 40 new Uint8Array(6) 6
    xgReadByte  107 24 new Uint8Array(6) 6
    mReadBytes  30 40 new Uint8Array(6) 6
    Acceleration  0 0 0
    Gyro          0 0 0
    Magnetometer  0 0 0
    187
    LSM9DS1 {
      "i2c": I2C {
        "_options": { "scl": B6, "sda": B9 }
       },
      "addr": 72, "gain": 2048,
      "gBias": [ 0, 0, 0 ],
      "aBias": [ 0, 0, 0 ],
      "mBias": [ 0, 0, 0 ],
      "gBiasRaw": [ 0, 0, 0 ],
      "aBiasRaw": [ 0, 0, 0 ],
      "mBiasRaw": [ 0, 0, 0 ],
      "commInterface": 0, "agAddress": 107, "mAddress": 30, "gyro_enabled": true, "gyro_enableX": true,
      "gyro_enableY": true, "gyro_enableZ": true, "gyro_scale": 245, "gyro_sampleRate": 6, "gyro_bandwidth": 0,
      "gyro_lowPowerEnable": false, "gyro_HPFEnable": false, "gyro_HPFCutoff": 0, "gyro_flipX": false, "gyro_flipY": false,
      "gyro_flipZ": false, "gyro_orientation": 0, "gyro_latchInterrupt": true, "accel_enabled": true, "accel_enableX": true,
      "accel_enableY": true, "accel_enableZ": true, "accel_scale": 2, "accel_sampleRate": 6, "accel_bandwidth": -1,
      "accel_highResEnable": false, "accel_highResBandwidth": 0, "mag_enabled": true, "mag_scale": 4, "mag_sampleRate": 7,
      "mag_tempCompensationEnable": false, "mag_XYPerformance": 3, "mag_ZPerformance": 3, "mag_lowPowerEnable": false, "mag_operatingMode": 0,
      "temp_enabled": true, "ax": 0, "ay": 0, "az": 0, "gx": 0,
      "gy": 0, "gz": 0, "mx": 0, "my": 0, "mz": 0 }
    
    

    1 Attachment

About