• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MKT-porter
博客园    首页    新随笔    联系   管理    订阅  订阅
树莓派mpu9250

https://www.instructables.com/How-to-Connect-MPU9250-and-Raspberry-Pi-Part-1/

 

 

Step 2: Library and System Setup

  • 从桌面环境中的“首选项”菜单打开 Raspberry Pi 配置工具,或者在终端中运行sudo raspi-config 。
  • 导航至界面选项。
  • 选择I2C并启用它。
  • 重新启动你的 Raspberry Pi。
  • 更新您的软件包列表:sudo apt-get update
  • 如果还没有安装 Python 的包管理器,请安装:sudo apt-get install python3-pip
  • 安装 I2C 所需的 Python 库:sudo pip3 install smbus2
  • 安装专门针对 MPU9250 的库,例如mpu9250-jmdev:sudo pip3 install mpu9250-jmdev

 

 

import time
from mpu9250_jmdev.registers import *
from mpu9250_jmdev.mpu_9250 import MPU9250

# Create an MPU9250 instance
mpu = MPU9250(
    address_ak=AK8963_ADDRESS,
    address_mpu_master=MPU9050_ADDRESS_68,  # In case the MPU9250 is connected to another I2C device
    address_mpu_slave=None,
    bus=1,
    gfs=GFS_1000,
    afs=AFS_8G,
    mfs=AK8963_BIT_16,
    mode=AK8963_MODE_C100HZ)

# Configure the MPU9250
mpu.configure()

while True:
    # Read the accelerometer, gyroscope, and magnetometer values
    accel_data = mpu.readAccelerometerMaster()
    gyro_data = mpu.readGyroscopeMaster()
    mag_data = mpu.readMagnetometerMaster()

    # Print the sensor values

  

posted on 2025-05-06 21:53  MKT-porter  阅读(66)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3