One of the widely used IMU(Inertial Measurement Unit) chip is MPU-6050. It contains gyroscopes combined with accelerometers and universally used in smart phones, video game remotes, quad-copters, etc. It is very inexpensive and easy to setup with all resources online.
Wiring with Arduino Mega 2560
A gyroscope (from Greek γῦρος gûros, “circle” and σκοπέω skopéō, “to look”) is a spinning wheel or disc in which the axis of rotation is free to assume any orientation by itself.- from wikiPedia.
The MPU-6050 acts as a slave to the Arduino with the SDA and SCL pins connected to the I2C-bus. Beside the normal I2C-bus, it has it’s own I2C controller, to be a master on a second(sub) I2C-bus. It uses the pins AUX_DA (XDA) and AUX_CL (XCL) for that second (sub)-I2C-bus which allows it to control, for example, a magnetometer. The values of the magnetometer can be passed on to the Uno-R3.
The following is the wiring:
|VCC||3.3V or 5V||3.3V or 5V|
|SCL||Pin 21 (SCL)||A5|
|SDA||Pin 20 (SDA)||A4|
|INT||Pin 2 (Interrupt 0)||2|
NB: 5V is prefered for GY521.
Libraries and Sketch Code
Use I2C Scanner to Check the Wiring.
Refer to link here for instruction. It will find your GY-521 at the address 0x68 or 0x69. Notes: MPU6050 LED light should light up.
Arduino Library with Examples
Download the I2C Device Library (i2cdevlib ) master zip file and extract the contents to a convenient location on your hard-drive. Copy MPU6050 and I2Cdev libraries from Jeff Rowberg, and put them into the Arduino library. Compile and upload the two examples (Examples/MPU6050/Examples/) and monitor the output. NB: Download the I2C Device Library ( i2cdevlib ) master zip file and extract the contents to a convenient location on your hard-drive.
To install the toxic library just copy the contents of the zip file to the library folder in Processing projects directory (sketchbook under Preference).
tan@taurus ~/proj/processing/sketchbook$ ls
examples libraries modes MPUTeapot tools
Also create a folder named MPUTeapot in the Processing projects folder and copy the MPUTeapot.pde file to that folder from MPU6050 example code location.
Now you have to do the following changes in the Jeff’s MPU6050_DMF code.
- Comment the line : #define OUTPUT_READABLE_YAWPITCHROLL
- Uncomment the line : #define OUTPUT_TEAPOT
- Now load the updated MPU6050_DMP code to Arduino.
- Run the MPUTeapot.pde in Processing
- You’ll see the small plane moving