MPU-9150 Hookup Guide
The MPU-9150 is a nine degrees of freedom (9DOF) inertial measurement unit (IMU) in a sigle package. It houses a 3-axis accelerometer, 3-axis gyroscope, 3-axis magnetometer and a Digital Motion Processor™ (DMP™) hardware accelerator engine. The range of each sensor is configurable: the accelerometer's scale can be set to ±2g, ±4g, ±6g, ±8g, or ±16g, the gyroscope supports ±250, ±500, and ±2000 °/s, and the magnetometer has full-scale range of ±1200µT (±12 gauss).
The MPU-9150 supports I2C. There is a single reference to in the datasheet for SPI, but all other evidence points to the contrary. We have only testing using I2C, and, for the purposes of this tutorial, we will only be covering how to use this device in I2C mode.
Covered In This Tutorial
This tutorial is devoted to all things MPU-9150. First we'll introduce you to the breakout board. Then we'll switch over to example code and show you how to interface with the board using an Arduino and our [SFE_MPU-9150 Arduino library](https://cdn.sparkfun.com/assets/learn_tutorials/3/9/7/MPU-9150_libraries.zip).
The tutorial is split into the following sections:
- Breakout Board Overview -- This page examines the MPU-9150 Breakout Board -- topics like the pinout, jumpers, and schematic are covered.
- Hardware Assembly -- How to assemble the hardware to run some example code.
- Installing the Arduino Library -- How to install the Arduino library, and use a simple example sketch to verify that your hookup works.
- Resources & Going Further -- Resources for learning and doing more with the MPU-9150.
This tutorial explains how to use the MPU-9150 Breakout Board with an Arduino. To follow along, you'll need the following materials:
If you're not familiar with some of the concepts below, we recommend checking out that tutorial before continuing on.
In total, the MPU-9150 Breakout breaks out 11 pins.
The bare-minimum connections required are broken out on the left side of the board. These are the power and I2C pins (the communication interface the board defaults to):
|Pin Label||Pin Function||Notes|
|GND||Ground||0V voltage supply|
|VCC||Power Supply||Supply voltage to the chip. Should be regulated between 2.375V and 3.465V.|
|SDA||I2C: Serial Data||I2C: Serial data (bi-directional)|
|SCL||Serial Clock||I2C serial clock (up to 400kHz)|
The remaining pins break out additional functionality and interrupt outputs:
|Pin Label||Pin Function||Notes|
|ESD||Auxiliary I2C master serial data||9150 can act as a master or pass-through to additional I2C devices.|
|ESC||Auxiliary I2C master serial clock||9150 can act as a master or pass-through to additional I2C devices.|
|COUT||Clock output||Outputs a 50% duty cycle square wave (see register map).|
|CIN||Clock input||Optional external reference clock input, grounded through jumper.|
I using an external clock source, cut 'CLK' jumper.
|AD0||I2C Slave Address LSB||If low I2C address is 0x68, else 0x69. Connected to jumper. (0x68 default)|
|FSYNC||Frame synchronization||External frame sync input that latches to capture external bus interrupts|
If using this pin cut 'SYNC' jumper.
|INT||Interrupt pin||Configurable digital output to signal the host processor of an event.|
The VCC and GND pins are where you'll supply a voltage and 0V reference to the IC. The breakout board does not regulate this voltage, so make sure it falls within the allowed supply voltage range of the MPU-9150: 2.375V to 3.465V. Logic voltage levels can be as low as 1.8V ±5% up to VCC.
The communication pins are not 5V tolerant, so they'll need to be regulated to within a few mV of VDD.
SDA, SCL, ESD, and ESC are used for the I2C interfaces. The auxiliary clock and data pins will require external pull-up resistors. These ave to be tuned on a case-by-case basis depending on bus capacitance to get proper rise times.
SDA and SCL have integrated 10KΩ pull-ups. If you plan on using more than one I2C device on the bus, you might want to remove these pull-ups. If the I2C lines are pulled-up too strongly by multiple sets of pull-ups, the bus will likely be out of spec and not function correctly.
The following image shows a stock PCBA on the left, and one with the pull-up resistors removed on the right. To remove these, I recommend reflowing a fair amount of solder onto the resistors. It doens't take very long to fully cover all 4 joints with molten solder and the two part will slide right off. So easily in my case that I wasn't able to capture a picture of the excess solder before the parts had come off. Wick off the excess solder, wipe clean with some DI water, and you are done.
There are a variety of interrupts on the MPU-9150. While connecting up to these is not as critical as the communication or power supply pins, using them will help you get the most out of the chip. The INT pin is a digital output to the host controller. The FSYNC pin can be configured as an interrupt input to optionally be passed through out the INT pin.
These can be programmed to interrupt as either active-high or active-low. More details on these configurations can be found in the product register map.
The most commonly used jumper will be to the address pin (AD0). It defaults to being pulled to ground selecting address 0x68, but with a soldering iron can be changed to be pulled up, switching the I2C address to 0x69.
The intention of these jumpers is to make it as easy-as-possible to use the board; using as few wires as possible. The CLK jumper is used to ground the external clock input as the datasheet recommends when not using an external clock. Make sure to cut this jumper if you attach an external clock to the CIN connection. The SYNC jumper ties FSYNC to ground as the manufacturer instructs one to do when not using it. Make sure to cut this jumper if use the FSYNC through hole connection.
To disable any of these jumpers, whip out your handy hobby knife, and carefully cut the small traces between middle pad and edge pads.
Be very careful trusting the datasheet. It's full of inconsistencies or lacking clarification. For example pin 22. There is a single reference to it functioning as a clock output (next image). There are several places stating that it's not to be used, such as the table shown two images below.
The register map reads "This bit also enables the clock output.", but that's the only reference. It's not even specified clearly to which bit they are referring. We were able to test this, and sure enough it outputs a clock. Maybe this clock is is okay to use. Maybe it was designed for factory testing only.
SPI is another example of being poorly documented. The following image implies that the address selection line is also SDO. The digital IO power supply pin is also the chip select line. Most serial peripherals we are familiar with don't source power out their chip select pins.
Finally one last quote to show how amazing the datasheet is: "The internal registers and memory of the MPU-9150 can be accessed using either I2C at 400 kHz." Either fast mode I2C, or what? As often as we tell you to RTFM, sometimes the manual can be misleading.
The basic use case for the MPU-9150 requires four connections to the µController or µProcessor; power, ground, I2C clock and data. The following images shows how we used a SparkFun FTDI Basic Breakout, and an 3.3V Arduino Pro Mini to power and interface to an MPU-9150. The demo required the use of an interrupt (right-most yellow jumper) connected to D2 (INT0).
Make connections to the breakout anyway that makes you happy. The board in the above photo has a right angle header soldered to it. We could have used a straight header, or wire, etc. Please note that different mounting orientations will alter the orientation of the axes. Make sure your code matches the physical orientation for your projects.
For this demo, we made the following connections:
|Arduino Pro Mini||MPU‑9150 Breakout||Notes|
|SDA||SDA||Serial data @ +3.3V CMOS logic|
|SCL||SCL||Serial clock @ +3.3V CMOS logic|
|D2||INT||INT0 on Arduino | Interrupt output "totem pole or open-drain" on MPU-9150|
The whole system in our testing was powered via USB through the FTDI basic.
Installing the Arduino Library
Download and Install the Library
Visit the GitHub repository to download the most recent version of the libraries, or click the link below:
For help installing the library, check out our Installing an Arduino Library tutorial. You'll need to move/copy the both the I2Cdev and MPU6050 directories inside the firmware directory into the libraries directory within your Arduino sketchbook. If you don't have a directory called libraries, create one and drop both directories in there.
The example Arduino code allows you to do things like print raw accelerometer, gyro, and magnetometer data. The original library came from i2cdevlib.com and was based on the very similar MPU-6050, which only used an accelerometer and gyro. The MPU-6050 device library was modified to include raw magnetometer data for the MPU-9150.
Running the MPU6050_DMP6 Example
Now, you can now run the example sketches. Open File ⇒ Examples ⇒ MPU6050 ⇒ Examples ⇒ MPU6050_DMP6. By default, this sketch is configured to do a fun teapot demo that uses processing. That's a little more involved than the scope of this hookup guide. We will output the acceleration components with gravity removed.
Uncomment line 102
//#define OUTPUT_READABLE_REALACCEL. Comment out line 112
#define OUTPUT_TEAPOT. Compile and upload the sketch. When it finishes uploading, open the serial monitor, and set the baud rate to 115200 baud. You should see this:
Initializing I2C devices... Testing device connections... MPU6050 connection successful Send any character to begin DMP programming and demo:
At the top of the serial monitor type any 'normal' character (such as alphanumeric) and press Send. Your system should respond with:
Initializing DMP... Enabling DMP... Enabling interrupt detection (Arduino external interrupt 0)... DMP ready! Waiting for first interrupt...
If you have the interrupt line connected properly, you should see lines similar to this:
areal -8680 1460 -1448 areal -9721 1460 -1463 ...
Resources and Going Further
Hopefully that info dump was enough to get you rolling with the MPU-9150. If you need any more information, here are some more resources:
- MPU-9150 Product GitHub Repository -- Your revision-controled source for all things MPU-9150. Here you'll find our most up-to-date hardware layouts and code.
- MPU-9150 Datasheet -- This datasheet covers everything from the hardware and pinout of the IC, to the register mapping of the gyroscope, accelerometer, and magnetometer.
- MPU-9150 Register Map -- This document covers all of the registers in the MPU-9150 and is a must read if you want all of the information. It clarifies inconsistencies in the datasheet.
- MPU-9150 Breakout Schematic
- MPU-9150 Breakout EAGLE Files
Now that you've got the MPU-9150 up-and-running, what project are you going to incorporate motion-sensing into? Need a little inspiration? Check out some of these tutorials!