Having trouble reading MPU6050 sensor via I²C on Pine64
#1
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!
  Reply
#2
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.
  Reply
#3
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)
  Reply
#4
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.
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  reading the inserted SSD gilwood 1 3,144 01-01-2022, 12:11 AM
Last Post: ryo
  Wi-Fi/Bluetooth for PINE64, Model: Sopine A64 lamson 0 2,988 08-24-2021, 08:17 AM
Last Post: lamson
  AC Adapter Which One? Pine64 A64 DB V1.1 2GB REV B (Year 2016) databaseprogrammer 2 5,574 06-17-2021, 05:35 AM
Last Post: kqlnut
  Just discovered Pine64 ! - first Q philip_rhoades 4 8,536 04-29-2020, 10:13 AM
Last Post: tophneal
  A newest user in Pine64 Aliko 1 5,625 04-19-2020, 10:33 PM
Last Post: tllim
  PINE64 Installer - Simple Way to Image Your MicroSD pineadmin 101 189,359 01-15-2020, 12:46 PM
Last Post: tophneal
  Emails from pine64 received as spam by gmail Matan 2 12,530 08-21-2019, 08:30 AM
Last Post: Leiaz
  How to handle a Pine64 correctly gbjensen 6 20,362 03-28-2019, 11:43 PM
Last Post: InsideJob
Information Creating a NAS server in Pine64 javi_cala 4 10,810 01-21-2019, 02:03 AM
Last Post: bartes
  The 6 most common reasons why Pine64 won't boot Andrew2 109 266,348 10-11-2018, 11:35 PM
Last Post: Technolab88

Forum Jump:


Users browsing this thread: 1 Guest(s)