Arduino Playground - MPU-6050
Arduino Playground - MPU-6050
Arduino Playground - MPU-6050
Main Site Blog Playground Forum Labs Store Help | Sign in or Register
search
Navigation
Introduction It can be easy, or not Information and Programs Breakout boards Measurements Sketch
Introduction
The InvenSense MPU-6050 sensor contains a MEMS accelerometer and a MEMS gyro in a single chip. It is very accurate, since it contains 16-bits analog to digital conversion hardware for each channel. Therefor it captures the x, y, and z channel at the same time. The MPU-6050 is not expensive, since it combines both an accelerometer and a gyro.
playground.arduino.cc/Main/MPU-6050
1/13
4/11/13
playground.arduino.cc/Main/MPU-6050
2/13
4/11/13
Breakout boards.
There are a number of "breakout boards" or "sensor boards" with the MPU6050. Sparkfun SEN-11028 http://www.sparkfun.com/products/11028 With schematic and full information. This breakout board must be used with 3.3V. There is no voltage regulator and no I2C-level shifter on the board. The pull-up resistors for the I2C-bus are 10k. Pull-up resistors of 4k7 are preferred, so two extra 10k pull-up resistors could be added. Drotek IMU 10DOF - MPU6050 + HMC5883 + MS5611 http://www.drotek.fr/shop/en/62-imu-10dof-mpu6050-hmc5883ms5611.html This sensor board contains three sensors. A schematic is not provided. The interrupt ('INT') of the MPU-6050 is not made available. Therefor the FIFO and the Jeff Rowberg library can not be used. Drotek MPU-6050 Invensense http://www.drotek.fr/shop/en/42-mpu6050-gyro-accelerometer.html This breakout board contains a voltage regulator. It can be used with 3.3V and with 5V. A schematic is not provided. GY-521 This sensor board has a voltage regulator. So it can be used with 3.3V and with 5V. It has pull-up resistors of 2k2 on the I2C-bus. The value of 2k2 is rather low. If it is combined with other sensor board which have also pull-up resistors, the total pull-up impedance might be too low. This schematic is hard to find, so here is a copy: http://playground.arduino.cc/uploads/Main/MPU6050-V1-SCH.jpg GY-52 This sensor board has a voltage regulator. So it can be used with 3.3V and with 5V. The board was originally designed for the MPU-3050, therefor the text "MPU-3050" or "MPU-X050" is sometimes printed on the board. The pull-up resistors are sometimes 10k and sometimes 4k7. If they are 10k, two extra pull-up resistors of 10k to the 3.3V could be added (from the SDA and SCL to the 3.3V of the sensor board or the 3.3V of the Arduino). Flyduino MPU6050 Break Out onboard 3.3V reg http://flyduino.net/MPU6050-Break-Out-onboard-33V-reg_1 This sensor board contains a voltage regulator, so it can also be used with 5V. The pull-up resistors of the I2C-bus are 4k7. It is actually a GY52 breakout board. Flyduino 10DOF IMU GY-86 MPU6050+HMC5883l+MS5611 http://flyduino.net/10DOF-IMU-GY-86-MPU6050-HMC5883lMS5611_1 A sensor board with the MPU-6050 and a magnetometer and barometer. A schematic is not provided. The sensor board contains a voltage regulator, so it can be used with 5V. There seems to be also a level shifter on the board for the I2C-bus. The pull-up resistors for the I2C-bus seems to be 2k2, which is rather low.
playground.arduino.cc/Main/MPU-6050
3/13
4/11/13
Measurements.
The raw values raises questions in the forums, since the raw values might seem unstable. Below are the raw values of the sensor that I measured, so you can compare them with your own raw values. The raw values changes a lot due to a number of reasons. The default sensitivity is high, and the sensor returnes 16 bits, but the actual valid number of bits is less than 16 bits. Since they are 16 bits, a variation of 50 is just a very small variation. The next measurement were done in these conditions: The sensor was placed as horizontal as possible. It was placed on concreet, not a wooden table. During the measurements, there was no traffic in the street. An battery of 12V was used, not the less stable voltage from the USB bus. I used a battery instead of an adapter to avoid any mains noise. The circuit was on for 15 minutes, to stabalize any temperature influence. The room temperature was 25 degrees Celcius.
M P U 6 0 5 0 R e a da c c e l ,t e m pa n dg y r o ,e r r o r=0 a c c e lx , y , z :1 8 4 ,4 8 4 ,1 4 9 9 2 t e m p e r a t u r e :2 9 . 6 3 5d e g r e e sC e l s i u s g y r ox , y , z:3 6 7 ,2 2 0 ,8 1 2 , M P U 6 0 5 0 R e a da c c e l ,t e m pa n dg y r o ,e r r o r=0 a c c e lx , y , z :1 1 6 ,3 6 4 ,1 5 0 5 6 t e m p e r a t u r e :2 9 . 6 3 5d e g r e e sC e l s i u s g y r ox , y , z:3 7 3 ,2 2 6 ,7 6 6 , M P U 6 0 5 0 R e a da c c e l ,t e m pa n dg y r o ,e r r o r=0 a c c e lx , y , z :2 3 2 ,4 3 2 ,1 5 1 0 0 t e m p e r a t u r e :2 9 . 6 8 2d e g r e e sC e l s i u s g y r ox , y , z:3 8 2 ,2 3 2 ,7 9 0 , M P U 6 0 5 0 R e a da c c e l ,t e m pa n dg y r o ,e r r o r=0 a c c e lx , y , z :2 8 0 ,4 6 8 ,1 5 1 3 6 t e m p e r a t u r e :2 9 . 6 3 5d e g r e e sC e l s i u s g y r ox , y , z:3 6 8 ,2 1 1 ,8 2 0 , M P U 6 0 5 0 R e a da c c e l ,t e m pa n dg y r o ,e r r o r=0 a c c e lx , y , z :1 4 0 ,4 3 2 ,1 5 1 0 8 t e m p e r a t u r e :2 9 . 5 8 8d e g r e e sC e l s i u s g y r ox , y , z:3 8 8 ,2 0 3 ,8 0 6 , M P U 6 0 5 0 R e a da c c e l ,t e m pa n dg y r o ,e r r o r=0 a c c e lx , y , z :2 2 0 ,4 6 4 ,1 4 9 2 0 t e m p e r a t u r e :2 9 . 5 4 1d e g r e e sC e l s i u s g y r ox , y , z:3 7 4 ,1 9 6 ,7 7 4 ,
playground.arduino.cc/Main/MPU-6050
4/13
4/11/13
M P U 6 0 5 0
R e a da c c e l ,t e m pa n dg y r o ,e r r o r=0 a c c e lx , y , z :1 7 2 ,4 4 0 ,1 5 1 0 0 t e m p e r a t u r e :2 9 . 5 8 8d e g r e e sC e l s i u s g y r ox , y , z:3 6 3 ,2 0 0 ,7 6 9 ,
Sketch.
The sketch below is the code made with Arduino 1.0.1 and it uses I2C-bus communication. The code uses the Arduino functions as much as possible. It is just a simple and basic sketch to get the MPU-6050 working. The I2C-address depends on the AD0 pin of the sensor. If it is connected to ground, the address is 0x68. If it is connected to VLOGIC (+3.3V) it is 0x69. There are a few sensor boards with the MPU-6050 sensor already soldered on it. Some of those boards have a pull-down resistor at AD0 (address = 0x68), others have a pull-up resistor (address = 0x69). Search in the sketch for "MPU6050_I2C_ADDRESS" and set that to your own I2C address. A i2c_scanner can be used to check if the device is connected to the i2c bus. The acceleration and gyro values of the sketch are raw values, which are not yet compensated for offset. The very first acceleration and gyro values after power up are sometimes not valid. The sketch is about 7kbyte, and will fit in a ATmega8.
/ /M P U 6 0 5 0A c c e l e r o m e t e r+G y r o / // / / /B ya r d u i n o . c cu s e r" K r o d a l " . / /J u n e2 0 1 2 / /O p e nS o u r c e/P u b l i cD o m a i n / / / /U s i n gA r d u i n o1 . 0 . 1 / /I tw i l ln o tw o r kw i t ha no l d e rv e r s i o n , / /s i n c eW i r e . e n d T r a n s m i s s i o n ( )u s e sap a r a m e t e r / /t oh o l do rr e l e a s et h eI 2 Cb u s . / / / /D o c u m e n t a t i o n : / /-T h eI n v e n S e n s ed o c u m e n t s : / / -" M P U 6 0 0 0a n dM P U 6 0 5 0P r o d u c tS p e c i f i c a t i o n " , / / P S M P U 6 0 0 0 A . p d f / / -" M P U 6 0 0 0a n dM P U 6 0 5 0R e g i s t e rM a pa n dD e s c r i p t i o n s " , / / R M M P U 6 0 0 0 A . p d fo rR S M P U 6 0 0 0 A . p d f / / -" M P U 6 0 0 0 / M P U 6 0 5 09 A x i sE v a l u a t i o nB o a r dU s e rG u i d e " / / A N M P U 6 0 0 0 E V B . p d f / / / /T h ea c c u r a c yi s1 6 b i t s . / / / /T e m p e r a t u r es e n s o rf r o m4 0t o+ 8 5d e g r e e sC e l s i u s / / 3 4 0p e rd e g r e e s ,5 1 2a t3 5d e g r e e s . / / / /A tp o w e r u p ,a l lr e g i s t e r sa r ez e r o ,e x c e p tt h e s et w o : / / R e g i s t e r0 x 6 B( P W R _ M G M T _ 2 )=0 x 4 0 ( Ir e a dz e r o ) . / / R e g i s t e r0 x 7 5( W H O _ A M _ I ) =0 x 6 8 . / / # i n c l u d e< W i r e . h > / /T h en a m eo ft h es e n s o ri s" M P U 6 0 5 0 " . / /F o rp r o g r a mc o d e ,Io m i tt h e' ' , / /t h e r e f o rIu s et h en a m e" M P U 6 0 5 0 . . . . " . / /R e g i s t e rn a m e sa c c o r d i n gt ot h ed a t a s h e e t . / /A c c o r d i n gt ot h eI n v e n S e n s ed o c u m e n t / /" M P U 6 0 0 0a n dM P U 6 0 5 0R e g i s t e rM a p / /a n dD e s c r i p t i o n sR e v i s i o n3 . 2 " ,t h e r ea r en or e g i s t e r s / /a t0 x 0 2. . .0 x 1 8 ,b u ta c c o r d i n go t h e ri n f o r m a t i o n / /t h er e g i s t e r si nt h a tu n k n o w na r e aa r ef o rg a i n / /a n do f f s e t s . / / # d e f i n eM P U 6 0 5 0 _ A U X _ V D D I O 0 x 0 1 / /R / W # d e f i n eM P U 6 0 5 0 _ S M P L R T _ D I V 0 x 1 9 / /R / W # d e f i n eM P U 6 0 5 0 _ C O N F I G 0 x 1 A / /R / W # d e f i n eM P U 6 0 5 0 _ G Y R O _ C O N F I G 0 x 1 B / /R / W # d e f i n eM P U 6 0 5 0 _ A C C E L _ C O N F I G 0 x 1 C / /R / W # d e f i n eM P U 6 0 5 0 _ F F _ T H R 0 x 1 D / /R / W # d e f i n eM P U 6 0 5 0 _ F F _ D U R 0 x 1 E / /R / W # d e f i n eM P U 6 0 5 0 _ M O T _ T H R 0 x 1 F / /R / W
playground.arduino.cc/Main/MPU-6050
5/13
4/11/13
playground.arduino.cc/Main/MPU-6050
6/13
4/11/13
playground.arduino.cc/Main/MPU-6050
7/13
4/11/13
playground.arduino.cc/Main/MPU-6050
8/13
4/11/13
playground.arduino.cc/Main/MPU-6050
9/13
4/11/13
/ /m u s tb e0f o rM P U -
/ /1 :d i s a b l e / /1 :s a m p l ea n ds l e e p / /1 :s l e e pm o d e / /1 :r e s e tt od e f a u l t
/ /C o m b i n e dd e f i n i t i o n sf o rt h eC L K S E L # d e f i n eM P U 6 0 5 0 _ C L K S E L _ 0( 0 ) # d e f i n eM P U 6 0 5 0 _ C L K S E L _ 1( b i t ( M P U 6 0 5 0 _ C L K S E L 0 ) ) # d e f i n eM P U 6 0 5 0 _ C L K S E L _ 2( b i t ( M P U 6 0 5 0 _ C L K S E L 1 ) ) # d e f i n eM P U 6 0 5 0 _ C L K S E L _ 3 ( b i t ( M P U 6 0 5 0 _ C L K S E L 1 ) | b i t ( M P U 6 0 5 0 _ C L K S E L 0 ) ) # d e f i n eM P U 6 0 5 0 _ C L K S E L _ 4( b i t ( M P U 6 0 5 0 _ C L K S E L 2 ) ) # d e f i n eM P U 6 0 5 0 _ C L K S E L _ 5 ( b i t ( M P U 6 0 5 0 _ C L K S E L 2 ) | b i t ( M P U 6 0 5 0 _ C L K S E L 0 ) ) # d e f i n eM P U 6 0 5 0 _ C L K S E L _ 6 ( b i t ( M P U 6 0 5 0 _ C L K S E L 2 ) | b i t ( M P U 6 0 5 0 _ C L K S E L 1 ) ) # d e f i n eM P U 6 0 5 0 _ C L K S E L _ 7 ( b i t ( M P U 6 0 5 0 _ C L K S E L 2 ) | b i t ( M P U 6 0 5 0 _ C L K S E L 1 ) | b i t ( M P U 6 0 5 0 _ C L K S E L 0 ) ) / /A l t e r n a t i v en a m e sf o rt h ec o m b i n e dd e f i n i t i o n s # d e f i n eM P U 6 0 5 0 _ C L K S E L _ I N T E R N A L M P U 6 0 5 0 _ C L K S E L _ 0 # d e f i n eM P U 6 0 5 0 _ C L K S E L _ X M P U 6 0 5 0 _ C L K S E L _ 1 # d e f i n eM P U 6 0 5 0 _ C L K S E L _ Y M P U 6 0 5 0 _ C L K S E L _ 2 # d e f i n eM P U 6 0 5 0 _ C L K S E L _ Z M P U 6 0 5 0 _ C L K S E L _ 3 # d e f i n eM P U 6 0 5 0 _ C L K S E L _ E X T _ 3 2 K H Z M P U 6 0 5 0 _ C L K S E L _ 4 # d e f i n eM P U 6 0 5 0 _ C L K S E L _ E X T _ 1 9 _ 2 M H ZM P U 6 0 5 0 _ C L K S E L _ 5 # d e f i n eM P U 6 0 5 0 _ C L K S E L _ R E S E R V E D M P U 6 0 5 0 _ C L K S E L _ 6 # d e f i n eM P U 6 0 5 0 _ C L K S E L _ S T O P M P U 6 0 5 0 _ C L K S E L _ 7 / /P W R _ M G M T _ 2R e g i s t e r / /T h e s ea r et h en a m e sf o rt h eb i t s . / /U s et h e s eo n l yw i t ht h eb i t ( )m a c r o . # d e f i n eM P U 6 0 5 0 _ S T B Y _ Z G M P U 6 0 5 0 _ D 0 # d e f i n eM P U 6 0 5 0 _ S T B Y _ Y G M P U 6 0 5 0 _ D 1 # d e f i n eM P U 6 0 5 0 _ S T B Y _ X G M P U 6 0 5 0 _ D 2 # d e f i n eM P U 6 0 5 0 _ S T B Y _ Z A M P U 6 0 5 0 _ D 3
playground.arduino.cc/Main/MPU-6050
10/13
4/11/13
v o i dl o o p ( ) { i n te r r o r ;
playground.arduino.cc/Main/MPU-6050
11/13
4/11/13
playground.arduino.cc/Main/MPU-6050
12/13
4/11/13
playground.arduino.cc/Main/MPU-6050
13/13