You are reading a single comment by @QueensCrown and its replies. Click here to read the full conversation.
  • 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

About

Avatar for QueensCrown @QueensCrown started