About Jeff Rowberg’s I2C lib for the MPU-6050

Jeff Rowberg has written an excellent library for the MPU-6050. It encapsulates the basic functions and hides all the I2C traffic management. You can download the code directly from github. You’ll need the I2Cdev files and the MPU6050 stuff. Copy the files to Arduino’s workspace’s “libraries” directory (for example “My Documents\Arduino\libraries\“) under directories I2Cdev and MPU6050. If the “libraries” directory doesn’t exist, you need to create it.

Basically there are two ways to use the MPU-6050 with this library: 1) Include the “MPU6050.h” header for all the basic functionality that is also documented by the official Register map or 2) instead include the “MPU6050_6Axis_MotionApps20.h” header to gain access to the reverse engineered DMP (Digital Motion Processor) functionality.

The library’s code is documented in a way from which you can generate a nice HTML documentation using Doxygen. It looks a lot like JavaDoc. (The Doxygen installer puts the Doxygen user’s guide in HTML-format into program’s folder. For example in my case the folder “file:///C:/Program%20Files/doxygen/html/doxygen_usage.html“) In short: To create documentation from the code you’ll need to type two commands from the command line:  “doxygen -g configFile” and “doxygen configFile” (replace configFile by name of choice).

That, or you might just look at the readily available MPU-6050.h documentation online.

I think the best (and only) way to explore the DMP-functionality is to examine the Teapot demo. Just upload the example code to an Arduino. When connecting the MPU-6050 to an Arduino, remember also to connect the interrupt signal (INT pin on the MPU-6050 to Arduino Diecimila or UNO’s digital pin 2) as the MPU-6050 with DMP is set up to fire interrupts whenever it has data ready.

To visualize the Teapot on the PC, you’ll need to have Processing installed and copy an additional toxiclibs library into Processing’s workspace’s libraries folder (much like you had to add the MPU’s libaries to the Arduino IDE’s libraries folder). If the folder “Processing\libraries” doesn’t exist, you’ll have to create it. Then save the Teapot demo “MPUTeapot.pde” under “Processing\MPUTeapot” (or the Processing IDE will later ask you to move the file to this directory).

I made a few changes to the MPUTeapot demo as it – in my opinion – didn’t properly catch the data packages sent by the Arduino..

InvenSense also has an official Teapot demo. I tried to run it, but it seems I’m missing a winusb.dll and didn’t really bother to investigate further. It should work though – I’ve seen it on youtube 🙂


8 thoughts on “About Jeff Rowberg’s I2C lib for the MPU-6050

  1. You can run the official Teapot demo, just open the install file with admin premissions…you won;t get the error…

    • Hi,
      I’ve dowloaded the MPUTeapod.pde from github.
      Installed processing on my PC and successfully copied the toxic library into the library folder.

      I opened processing an opened the MPUTeapot and tries to runn it. It opens a box, but in the error screen I’ve got this message:

      OpenGL error 1282 at bot beginDraw(): invalid operation
      Stable Library
      Native lib Version = RXTX-2.1-7
      Java lib Version = RXTX-2.1-7
      [0] “COM1”
      [1] “COM3”
      OpenGL error 1282 at bot endDraw(): invalid operation

      • Hi, thanks for commenting.

        Sadly however, I don’t know what’s causing this error. Prior to playing around with the MPU-6050, I have no experience with toxiclibs or OpenGL. According to Google you’re not the only one to get this error message, but I didn’t see a quick fix when looking at the first few hits.

        Personally, I’ve encountered a “GLException: Unable to set pixel format…”, when attempting to run the MPUTeapot in Processing 2. In Processing 1.5.1 it runs fine, which is why I haven’t updated yet.

  2. My MPU6050 with DMP runs greatly (graphic output ist the MTUTeapot.pde).
    Now I have the problem that Pitch and Roll postition is directly opposite. e.g. when I Pitch down the MPU6050, the Teapot goes up. YAW is ok.
    How to modify the DMP quateriones output ?

    • I’m still trying to figure this one out myself 🙂

      You might want to look at these lines in the Processing sketch’s draw() function first:
      float[] axis = quat.toAxisAngle();
      rotate(axis[0], -axis[1], axis[3], axis[2]);

      Alternatively you could do some quaternion math, but I don’t think you can reconfigure what the DMPs outputs. (However I haven’t yet looked at the tools Invensense has published.)

  3. I only got the ‘teapot demo’ to work after MANY hours.
    My 6050 GY521 is connected as stated in this article.
    BTW you will need a reset button on the arduino (so the MiniPro will not work).
    Then make sure to edit the INO from https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050/Examples/MPU6050_DMP6
    to enable teapot format output by commenting out ‘yawpitch’ and uncommenting the ‘teapot lines like so:
    #define OUTPUT_TEAPOT
    Make sure the baud rates are the same in the INO and the PDE:
    Then run the processing PDE from the below link (with the library mentioned in the article installed):
    After a few seconds you should see a small window pop up with an airplane in it. If it does not move, just press the reset button on the arduino and the plane will start moving.
    I am running win7 32bit and Java V7, PROCESSING V2 and IDE v 1 05 . I also found that If I get Java error messages, the only way to correct this , is to reboot the PC.

    • Yep. The reset button comes in handy sometimes as opening a connection from Processing will not reset the Arduino (unlike in the Arduino IDE). Interesting to hear that you’ve managed to get it working with Processing 2.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s