Pages

Thursday 17 July 2014

Getting started with MPU-6050 IMU

It has been a while but I have been struggling to get this thing working and hopefully my instructions might help someone else out there.

So the MPU-6050 is an IMU unit which has an accelerometer and a gyroscope built into it and communicates over I2C, it also has some complex processor in there too called a DMP which filters and processes all the results but I haven't got that working yet - Maybe as this blog develops I will post about how I got it up and running but let us just concentrate on the basics for now.

I am using the GY-521 breakout board which I bought off eBay for a couple of quid.


Wiring

The board communicates over I2C and it has internal pull up resistors built in so all you have to do is connect the following. Note that the SDA and SCL lines will be specific to your microcontroller I am using a PSoC 4 Pioneer board but I also tested it on an Arduino UNO)

  • VCC - 5V (I have not tested 3.3V)
  • GND - 0V
  • SDA - SDA on your microcontroller (P0[5] on PSoC 4)
  • SCL - SCL on your microcontroller (P0[4] on PSoC 4)

Here it is connected to the PSoC 4

Software

Here is where things get interesting because it is very easy to get communicating and get the raw values out of the sensor but actually understanding those values, filtering them and getting useful data from them is a different story.

Let us just start though by seeing if we can get some values out of the chip.

Reading raw data

Jeff Rowberg has created a nice library for the MPU-6050 on his Github it is an extensive I2C library for many other development boards and is definitely worth checking out. I am going to be using it in our project except as I am using a PSoC and not an Arduino or a MSP430 I will be using an edited version of the i2cdevlib designed to work with the PSoC 4 Pioneer which a kind individual named Hernán Sánchez released on the PSoC forums.

I have altered his project to display the values in a more useful way and also to move a lot of the extraneous code out to another source file, I think this will help you understand more what is happening.

You can find my getting started code on my Github under Examples "Getting Started"

Just connect a serial monitor (PuTTY) to the relevant port and you should see the connection being made and the raw values being printed to the screen.

In the next post I am going to look at turning the values into angles and accelerations but for now, keep watching the skies.

2 comments:

  1. Hi Sam,
    Greeting from Vietnam
    I'm working on MPU6050 project and your blog is really useful for me.
    I'm currently using MSP430 as my MCU and C as the programming language. At first, I found the I2CDeliv but it's using the C++ then fortunately I found your blog with the C version of MPU6050 library which help me much. I modified the i2c library in order to work with MPS430 and the problem came out.

    Here in this tutorial, you are using int16_t for ax,ay,az,gx,gy,gz . However the I2CReadBytes funtion read the accel and gyro data then save it in buffer which is of uint_8 .
    It's really hard for me to understand this stuff since I'm also new in programing.

    ReplyDelete
    Replies
    1. Hi Nguyễn

      The Function I2CReadBytes return 8-bit value , as the I2C send 1-byte per time so we read 1-byte each time . And to have the 16-bit value we read the data twice, one for each byte

      Delete