Skip to content

rpicopter/MotionSensorExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MotionSensorExample
===================

MPU6050/MPU6500/MPU9150/MPU9250 over I2c for RaspberryPi using official Invensense libraries (v5.1):
http://www.invensense.com/developers/index.php?_r=downloads


This is a sample program for testing your MPU Motion Sensor with Rasperry Pi.
It does all the initialization and gathers:
- gyro
- accel
- quaternion
- compass (for MPU9XXX)
- temperature

and calculates Yaw, Pitch, Roll in degrees which in turn is displayed as an output.


**Wiring**
I2C uses only2 wires for data transmission: SCL and SDA
RPi pin 3 -> MPU SDA
RPi pin 5 -> MPU SCL


You will also need to provide power (3.3V) to your MPU. You can use external power or hook it up with RPi.
For example:
RPi pin 1 (3.3V) -> MPU VCC
RPi pin 6 (Ground) -> MPU GND


**Compilation:**
On RPi, edit MotionSensor/Makefile and adjust CXX_OPTS to specify your board (-DMPU6050 for MPU6050, -DMPU9150 for MPU9150), issue make


**Cross compiling:**
Edit all Makefiles in all directories and adjust CXX. Issue make


**Running:**
  make sure you have i2c_dev module loaded (modprobe i2c_dev)
  run mstest
  
*Output:*
Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
Initializing DMP...
Enabling DMP...
DMP ready!
Initializing IMU...
Checking... Done.
IMU init done; offset values are :
yaw = -0.169205, pitch = -1.301078, roll = -1.168776

yaw = -0.174            pitch = 1.325           roll = -1.219   t = 20.24       1       0       0
yaw = -0.179            pitch = 1.350           roll = -1.267   t = 20.22       2       0       0
yaw = -0.185            pitch = 1.372           roll = -1.314   t = 20.23       3       0       0
yaw = -0.190            pitch = 1.395           roll = -1.361   t = 20.21       4       0       0
yaw = -0.195            pitch = 1.418           roll = -1.410   t = 20.23       5       0       0
yaw = -0.201            pitch = 1.441           roll = -1.454   t = 20.23       6       0       0
yaw = -0.206            pitch = 1.465           roll = -1.498   t = 20.23       7       0       0
yaw = -0.211            pitch = 1.485           roll = -1.545   t = 20.23       8       0       0
yaw = -0.216            pitch = 1.506           roll = -1.587   t = 20.23       9       0       0

....

**Additional info:**
Current setup is to run at 40Hz, this can be adjusted in the ms_open function, however note that your code will need to read the values with respective speed or quicker. Otherwise the MPU fifo buffer will overflown.

To read MPU see ms_update - it calls 'dmp read fifo' in a while loop. This means that if fifo is empty this will stall until a packet is available.

-------------------------
Gregory Dymarek

About

MPU6050/MPU6500/MPU9150/MPU9250 over I2c for RaspberryPi

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published