QueensCrown
Member since Sep 2019 • Last active Apr 2020Most recent activity
-
- 4 comments
- 1,940 views
-
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 codeI2C1.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]) ...
Sorry about my english I tried my best
-
Thank you for all responses,
They read the sensor ready data like this
I did:
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 get1414240
(Without converting to hex[ 20, 20, 36, 4, 10, 24, 72 ]
). In the driver I must get UINT8_C(0x60) or0x60
the thing is is0x60
equal to 1414240 ? or am I converting wrong?