I have the following code to use in a Microbit connecting to an MPU 6050 (on a gy521 board)
basic.showIcon(IconNames.Heart)
SSD1306oled.useBuffer();
const MPU = 0x68;
pins.i2cWriteNumber(MPU, 0x6B, NumberFormat.UInt8LE, true)
pins.i2cWriteNumber(MPU, 0x00, NumberFormat.UInt8LE, false)
basic.pause(10)
pins.i2cWriteNumber(MPU, 0x1B, NumberFormat.UInt8LE, true)
pins.i2cWriteNumber(MPU, 0x00, NumberFormat.UInt8LE, false)
basic.pause(10)
pins.i2cWriteNumber(MPU, 0x1C, NumberFormat.UInt8LE, true)
pins.i2cWriteNumber(MPU, 0x00, NumberFormat.UInt8LE, false)
basic.pause(10)
pins.i2cWriteNumber(MPU, 0x75, NumberFormat.UInt8LE, true)
let who = pins.i2cReadNumber(MPU, NumberFormat.UInt8LE, false)
SSD1306oled.drawTextAt("who: " + who, 8, 0)
SSD1306oled.drawBuffer()
basic.pause(2000)
basic.forever(function () {
pins.i2cWriteNumber(MPU, 0x41, NumberFormat.UInt8LE, true)
basic.pause(100)
let num1 = pins.i2cReadNumber(MPU, NumberFormat.UInt8LE, true)
let num2 = pins.i2cReadNumber(MPU, NumberFormat.UInt8LE, false)
SSD1306oled.drawTextAt(1 + "= " + num1, 0, 1)
SSD1306oled.drawTextAt(2 + "= " + num2, 0, 2)
SSD1306oled.drawBuffer();
basic.pause(500);
})
It can read the "who am I" register (0x75) just fine, but shows zeros for accelerometer, gyro, and even temperature. I've gotten to this point by trying to adapt Arduino code to microbit typescript. I had thought the problem might be there is no "Wire.requestFrom" in microbit typescript, but then I can read "who am I" just fine, so I think it must be something else. I thought maybe I had a defective board, so I bought another - same results.
I have perused the register map (https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf) but nothing is jumping out at me.
I tried someone else's library, but it appears un-maintained / maybe broken (his "initialize" function, which is referenced in his examples, no longer exists... copying it and enabling "initialize" doesn't help).
I am pretty much at a loss. Any ideas?
(BTW, the SSD1306oled functions just write to an LED screen - might as well write to serial output or whatever for debugging)