GITLAB
pyp / Blog_Lcj
User activity
You won’t be able to pull or push project code via SSH until you add an SSH key to your profile
Don’t show again | Remind later
Project
Files
Commits
Network
Graphs
Issues 0
Merge Requests 0
Wiki
Settings
Home
Pages
Git Access
MPU 6050
树莓派pi3使用I2C获取MPU6050九轴传感器数据
1. 首先要启动树莓派的I2C功能
sudo mount /dev/mmcblk0p1 /mnt/
cd /mnt
sudo vim config.txt
找到下面两行
火狐截图_2016-06-17T10-43-56.664Z
将注释符号#删掉,如果没有上面两行则自己编辑保存。然后reboot系统。
安装i2c-tools
sudo apt-get install i2c-tools
连接MPU6050设备,并测试I2C驱动是否已经启动
接线需要四根:电源正3.3V,Ground,SCL,SDA。
MPU6050模块上会有标志,与树莓派对齐用杜邦线接好即可。
树莓派3的IO定义如图:
屏幕快照 2016-06-17 下午6.44.14
连接好设备后,通过命令:
i2cdetect -l
查看设备是否已正常工作。如果你的树莓派只接了MPU6050一个I2C设备,对应设备文件为:/dev/i2c-1
屏幕快照 2016-06-17 下午6.44.24
至此I2C驱动已开启,设备工作正常,可以继续写代码访问数据了。
代码和测试
ssh或者serial登陆到树莓派2,clone程序MotionSensorExample:
git clone https://github.com/uname/MotionSensorExample
cd MotionSensorExample
make
屏幕快照 2016-06-17 下午6.44.34
6. 其他
MotionSensorExample通过条件编译的方式来支持不同的MPU(6050/6500/9150/9250),只要修改位于MotionSensorExample MotionSenso下的Makefile即可:
CXX_OPTS=-c -DMPU6050 -DMPU_DEBUGOFF -I../libs/
Last edited by pyp 2 months ago