2.1.36. Exercise: MPU6050 IMU I2C Module Objective

Communicate digital data between an Arduino and a MPU6050 inertial motion sensor over a I2C bus.

Please be sure to review the general information about I2C and SPI in the previous exercise prior to starting this one.

This exercise will use a MPU6050 I2C Accelerometer/Gyro inertial sensor module from Sparkfun. This modules is based on the InvenSense MPU-6050 Motion Processing Unit. Example Arduino code is available from github as part of the larger i2cdevlib, which provides drivers for many I2C devices. Steps and observations

  1. Download or find the complete MPU6050_DMP6 sketch. This is an example from i2cdevlib, reorganized into a self-contained sketch. Be sure to fetch all top-level files.
  2. Plug the IMU module into a breadboard and use solid wire to make the following five connections from the Arduino to the module. Note carefully that this module uses 3.3V, unlike the previous example:
    1. 3.3V -> VCC
    2. GND -> GND
    3. A4 -> SDA
    4. A5 -> SCL
    5. D2 -> INT
  3. Attach the Arduino to your computer and install the sketch.
  4. Open the Arduino IDE Serial Monitor and make sure it is set to 115200 baud.
  5. Reset the Arduino. You should see a wakeup message on the console followed by the following prompt: Send any character to begin DMP programming and demo:
  6. Type a character in the input box and press enter.
  7. You should see a rapid series of messages in the following form: ypr    -87.92  74.39   1.85
  8. Physically rotate the IMU and watch the numbers change. Comments

The sketch is a relatively complex piece of software for a microcontroller, and it uses more than half of the available Arduino Uno program space. But it is also solving a complex example of processing 3D motion data.

For a challenge, clone the original i2cdev library from github and install it in your Arduino IDE libraries path, then try compiling the original unmodified example. Arduino Code

  1. Documentation: MPU6050_DMP6 Arduino Sketch
  2. Sketch Folder: MPU6050_DMP6