Having trouble reading MPU6050 sensor via I²C on Pine64
#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


Messages In This Thread
RE: Having trouble reading MPU6050 sensor via I²C on Pine64 - by congb - 10-20-2025, 08:24 PM

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,351 01-15-2020, 12:46 PM
Last Post: tophneal
  Emails from pine64 received as spam by gmail Matan 2 12,527 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,322 10-11-2018, 11:35 PM
Last Post: Technolab88

Forum Jump:


Users browsing this thread: 1 Guest(s)