0 Replies Latest reply on Jun 11, 2015 5:30 PM by LuigiC

    MPU6050 on Edison's breakoutboard through I2C-6


      A couple weeks ago I got my hands on a cheap gyroscope for Arduino, and I decided to give it a shot with the Edison. This is my findings on working with this module and the resulting source code is available on GitHub: runluigi/EdisonGY521 · GitHub


      A link to buy this tiny board on ebay:

      GY 521 MPU 6050 Module 3 Axis Gyro 3 Axis Accelerometer Module for Arduino | eBay


      You will also need a logic level converter to operate at the right voltage:

      5V to 3 3V IIC I2C Logic Level Converter Bi Directional Module for Arduino | eBay


      First of all, I think the biggest challenge for people is always the beginning. In this case is how to connect things and how to start building on top of it. So lets break this down into sections.


      Hardware setup.

      I am not gonna dwell to much into this, but we can discuss this on the thread. Here are some pictures:






      Code explanation.


      On your main program you want to include MPU6050.h, which can be found on the repository that was mentioned before.


      On your main process you want to have something like this


      int main(){

          cout << "WELCOME TO MPU6050 MARK 2"<<std::endl;

          MPU6050 gyro;// you create an object that will communicate of class MPU6050.

          if( gyro.initialize() == 1) //run the initialize function to get the ID and ensure everything you have communications with MPU6050

                      cout <<"INITIALIZED ID:"<< (int) gyro.getId() << std::endl;


          cout<<"SAMPLE RATE IS:"<<gyro.getSamplerate()<<" kHz"<<std::endl;

          gyro.setGyroConfig(24);//set the sensitivity for gyroscope


          cout<<"GYRO CONFIG:"<<(int)gyro.readGyroConfig()<< std::endl;//read configurations


          gyro.calibrate(); //calibrate proccess will take an average of the bias values of the gyroscope


          for(int i = 0;i<500;i++){//finally you can get into a loop and poll the values of the gyroscope


                // some task here.

               cout<<"Raw values:"<<gyro.getReadings()<<std::endl; //you can see the raw values by printing the getter getReadings()

               cout<<"Calibrrated values:"<<gyro.getCalibratedReading()<<std::endl; ////or the calibrated values by printing the getter getCalibratedReadings()

              usleep(10000); //you can poll every 10ms without a problem.




      The functions gyro.getReadings() and gyro.getCalibratedReading() return a structure MPU6050Reading that looks like this:


      struct MPU6050Reading{

              int x_accel;

              int y_accel;

              int z_accel;

              int temperature;

              int x_gyro;

              int y_gyro;

              int z_gyro;



      This means you could do something like this:

      for(int i = 0;i<500;i++){


                // some task here.

               cout<<"X_ACCEL:"<<gyro.getReadings().x_accel<<std::endl; //access individual values of MPU6050Reading

              usleep(10000); //you can poll every 10ms without a problem.



      Future plans.

      1- I want to design a single layer board to ditch the perfboard and plug the Edisons mini-breakoutboard directly, but I am not too familiar with eagle and I am limited in the time I can invest to this project.

      2- Considering on writing a kernel driver to access this values from user space.

      3- Expand the code to support the rest of the functions in the GY521. For example the Slave I2C and such different sample rates and what not.


      If you have comments or improvements to my setup please don't hessitate to pos them.