PINE64
Having trouble reading MPU6050 sensor via I²C on Pine64 - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: General (https://forum.pine64.org/forumdisplay.php?fid=1)
+--- Forum: Getting Started (https://forum.pine64.org/forumdisplay.php?fid=21)
+--- Thread: Having trouble reading MPU6050 sensor via I²C on Pine64 (/showthread.php?tid=19979)



Having trouble reading MPU6050 sensor via I²C on Pine64 - Jaxon - 09-04-2025

Hello everyone,

I’m trying to read data from the MPU6050 6-axis sensor via I²C on my Pine64 board, but I’m running into some issues.

System: Armbian

I²C is already enabled, and I can see the device address 0x68 with i2cdetect -y 1

My Python script runs, but the data I get is unstable and often jumps around

Has anyone successfully driven the MPU6050 on Pine64? Do I need any additional configuration?

Thanks!


RE: Having trouble reading MPU6050 sensor via I²C on Pine64 - Alex92 - 09-05-2025

I had the same problem when working with the MPU6050 on a Pine64 board, and a few things made the difference:

Use 3.3 V instead of 5 V to avoid level shifting issues.

On initialization, write to register 0x6B (as described in the MPU6050 datasheet) to wake the device from sleep mode.

To smooth out the jitter, apply a simple moving average or even a Kalman filter depending on your needs.

Once I followed the datasheet’s register setup and wiring, the readings became much more stable.


RE: Having trouble reading MPU6050 sensor via I²C on Pine64 - congb - 10-20-2025

Make sure you're using a reliable library like smbus2 or Adafruit_CircuitPython_MPU6050.
Here's a simple example using smbus2:
Code:
import smbus2
import time

bus = smbus2.SMBus(1)
address = 0x68

# Wake up MPU6050
bus.write_byte_data(address, 0x6B, 0)

def read_word(adr):
    high = bus.read_byte_data(address, adr)
    low = bus.read_byte_data(address, adr+1)
    val = (high << 8) + low
    return val

def read_word_2c(adr):
    val = read_word(adr)
    if (val >= 0x8000):
        return -((65535 - val) + 1)
    else:
        return val

while True:
    accel_x = read_word_2c(0x3B)
    print("Accel X: ", accel_x)
    time.sleep(0.5)



RE: Having trouble reading MPU6050 sensor via I²C on Pine64 - biketool - 10-21-2025

If you or anyone reading this have the skills a joystick driver for the gyros would make playing games and emulator much better than using an external device.