Home / Tutorials / BeagleBone Tutorial / Beaglebone Black MPU6050 Interfacing: I2C Tutorial Part 2
beaglebone black mpu6050 tutorial

Beaglebone Black MPU6050 Interfacing: I2C Tutorial Part 2

We covered the Beaglebone Black I2C basics in our last tutorial. This time, we’ll try to communicate with a device through the I2C protocol. This device, the MPU6050, is a gyroscope + accelerometer integrated circuit that is very popular among makers and enthusiasts.

Beaglebone Black MPU6050 Wiring Diagram

First thing you need to do, of course, is connect the MPU6050 to the Beaglebone Black. We will be using I2C-2 bus of the BBB (as per the previous tutorial) and so our SDA pin will be P9_20 while our SCL pin will be P9_19. Also, connect the MPU6050 VCC pin to the P9_4 (3.3 V VDD) and its ground pin to P9_2 (DGND). Here’s the fritzing diagram:

beaglebone black mpu6050 wiring

[the_ad id=”3059″]

You can check if your connections are correct using the command i2cdetect -r 2:

You’ll see that address 68 is filled out. That’s the MPU6050!

The MPU6050 Registers

Accelerometer and Gyroscope

The MPU6050 has registers from 0x0D to 0x75. Each of these registers are 8-bits wide and have specific functions. To see all of these registers, download the MPU6050 register map.

[the_ad id=”3059″]

For the purpose of this tutorial, we’ll be reading from the accelerometer and gyroscope registers. The accelerometer and gyroscope data are 16 bits wide and so data from each axis uses two registers. Here’s what I’m talking about:

Register Address

We can check out the contents of these registers through i2cdump:

Here you’ll see that the registers on the table above have zero values. This is because we need to wake the MPU6050 up before it gives data.

How to Wake Up the MPU6050

[the_ad id=”3059″]

To wake up the MPU6050, we need to write zero to the PWR_MGMT_1 register which is at address 0x6B. Here’s how to do that:

After that, we can use i2cdump again to check.

The accelerometer and gyroscope registers now have values!

Try reorienting the MPU6050 and do the i2cdump again. You should have different values on the accelerometer and gyroscope registers.

Getting Individual Values

To get an individual register value, we can use the i2cget command. For example, I’ll read the value of ACCEL_XOUT_H register (address 0x3B):

The output 0x30 is the high byte of the MPU6050’s acceleration in the x-axis. To get the low byte simply change the address:

The low byte is 0xf8. This means the acceleration in the x-axis is 0x30f8 or 12, 536 in decimals.

Scaling the MPU6050 Raw Data

What we’ve read from the MPU6050 so far is raw data and needs to be converted to make sense. The acceleration data is measured in g (acceleration due to gravity) units while the gyroscope data is measured in degrees per second. The MPU6050 uses 2g and 250 deg/sec as default sensitivities.

[the_ad id=”3059″]

Since each axes is 16 bytes and is signed, the raw values will range from -32,768 to 32, 767. This means acceleration in axes X ,Y and Z should have values within these ranges that represent the effect of gravity. For the default sensitivity which is 2g, the scaling factor should be around 16, 384 (32, 768/2).

In the same way, the X, Y and Z gyro data should have raw data readings from +250 to -250. According to the datasheet, the best scaling factor to use is 131.

However, even with scaling factors you may not get the exact acceleration and rotational speed since there will always be noise and sensor reading errors.

C++ Code

Following the discussion above, we can now write a C++ code that displays the accelerometer and gyroscope values:

[the_ad id=”3059″]

You can now use your MPU6050 to create motion-based apps for the Beaglebone Black!

If you find this post useful, kindly post a comment below. Come back to this site for more updates!

Check Also

beaglebone black adc

Controlling a Servo Motor with BoneScript

Using the Beaglebone Black’s PWM Bonescript also includes an analogWrite function which utilizes the 8 …


  1. its realy useful
    thanks a lot

  2. Sharmad Tadkodkar

    how do i use these values of accelerometer/gyro in a python code?

  3. Thank you! Nice and helpful tutorial.

  4. Thanks for this tutorial. Using this tutorial and the sample code, was able to connect ICM20601 and see the data. Very useful.

Leave a Reply

Your email address will not be published.