bmi160

Posted on
  • Hi, I bought bosh bmi160 Gyro & accelerometer but I couldnt find any module in espruino module page. I did some research found docs for sensor. I tried i2c connection I am able to write data and see data changing with different commands given in docs. The problem is when I read console by interval function I get uint8Array I dont know what to do with it I tried to convert to hex I got different data with different commands. According to Bosh Docs (I put link to bottom) if I send 0x00 I will read chipId I sended code with following code

    I2C1.setup({ scl : NodeMCU.D6, sda: NodeMCU.D5});
    
    function toHexString (byteArray) {
      const chars = new Uint8Array(byteArray.length * 2);
      const alpha = 'a'.charCodeAt(0) - 10;
      const digit = '0'.charCodeAt(0);
    
      let p = 0;
      for (let i = 0; i < byteArray.length; i++) {
          let nibble = byteArray[i] >>> 4;
          chars[p++] = nibble > 9 ? nibble + alpha : nibble + digit;
          nibble = byteArray[i] & 0xF;
          chars[p++] = nibble > 9 ? nibble + alpha : nibble + digit;    
      }
      return String.fromCharCode.apply(null, chars);
    }
    
    setInterval(function() {
        var uint = I2C1.readFrom(0x69,16);
        var hex = toHexString(uint);
        console.log(uint);
        console.log(hex);
    })
    

    Result:

    d1210000000000000000000000000000
    
    new Uint8Array([209, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
    ...
    

    https://www.bosch-sensortec.com/media/bo­schsensortec/downloads/datasheets/bst-bm­i160-ds000.pdf#page=19

    Sorry about my english I tried my best

  • Hi,

    check the BoschSenortec github account, there is a completely BMI160 driver written in c (rewriting c code to javascript is not that hard).

    Hint: Start with Init the sensor and then try to Read some values.

  • You are on the right way, the 209 decimal in the response is 0b11010001 as shown on the datasheet screenshot!

  • Thank you for all responses,

    They read the sensor ready data like this

            rslt = bme280_set_regs(&reg_addr, &soft_rst_cmd, 1, dev);
    
           (rslt == BME280_OK)
           //BME280_OK = INT8_C(0)
    

    I did:

    var ERR_REG = 0x02;//According to docs at page 49
     var adr = 0x69;
     var len = 5;// 
    I2C1.writeTo(adr,ERR_REG);
      var response = toHexString(I2C1.readFrom(adr,16)).slice­(0,len);
       //Response = 00000
    

    If the data is correct 5 zero bit is tells sensor is working correct

    But when I tried to get chip id with same code with len = 7 I get 1414240 (Without converting to hex [ 20, 20, 36, 4, 10, 24, 72 ]). In the driver I must get UINT8_C(0x60) or 0x60 the thing is is 0x60 equal to 1414240 ? or am I converting wrong?


  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

bmi160

Posted by Avatar for QueensCrown @QueensCrown

Actions