A new IMU which I'm thinking of calling openIMU

I'm thinking openIMU in honor of freeIMU. Both are based on algorithms found at


The Madgwick algorithm is the IMU that I am using on my quad copter right now. I'm getting excellent results. This program is a work in progress to say the least. The code posted works great with the Pololu MinIMU9. For best results use a MEGA or Due. I am going to turn this into a library that will accept any sensor readings so long as the data is presented to the filter in the aircraft convention (NED). If you want to try this algorithm with a different IMU the code should be quite easy to modify. Just rememeber to put the sensor data into north, east, down convention. And please post here the results you had.

I am testing a simple two state Kalman filter that I will use to fuse data from the accelerometer and a barometer into an altimeter. I am almost finished with that part of the project. Once I am I am going to include that code into the IMU. This means the IMU will give pitch, roll, and yaw to within ~.25 degree or less accuracy as well as an altitude with a ~.5 meter accuracy.


Thanks for checking out my project and I'd love to hear your feedback.

Its always good to explain what letters such as these mean . There are many possibles http://en.wikipedia.org/wiki/IMU

I suspect in this case it is Inertial measurement unit

The code you provide is just to show data from the IMU, correct?

The user then would provide a seperate PID algorithm to use the data to stabilize their platform, correct?

I have the Pololu MinIMU 9 so, I have some ideas of how I would like to use your example and data collection is all I need at this point.

Thank you!

That is correct. The code just tracks your pitch, roll, and yaw angles. If you want to do controls based off it you can with no problems.

I never use the serial monitor in arduino. I think real term http://realterm.sourceforge.net/ is a much better option. If you capture the data as a .csv file you can open it in excel and make graphs etc.

Also, this code should work for either v1 or v2 of the board.

Thanks Mikesbaker!

Hey Mike,

I have been trying out your Pololu_Open_IMU from GIT Hub. The accelerometer values seem to work fine but I'm having a drift on my Yaw value.

With the IMU sitting flat on my desk I start this up and I can watch the value growing by about .1 every half a second this happens continually. I'm wondering if you have experienced this?

To correct the yaw problem change this line

if (loopCount == 40){//attempt full update at 10hz
        loopCount = 0;

To this:

if (loopCount == 32){//attempt full update at 10hz
        loopCount = 0;

I have updated the code in github. If you get unsatisfactory results or the system is taking up too much time the frequency of the updates can easily be changed by adjusting the loopCount comparisons. Thanks for your interest in the openIMU. I am working on porting the code to the razor 9dof board from sparkfun. Sorry for the slow reply. I now am being notified when a reply to this thread is made and I will be better at staying on to of my responses.

If that doesn't work try this:

void loop(){
  G_Dt = (micros() - timer)/1000000.0;

  if (millis() - printTimer > 50){
    printTimer = millis();


It will run the full update at the maximum rate possible. Please let me know how this works out for you.

I have ported the code out for the sparkfun Razor 10736 9dof IMU.


I have fixed the bugs in the pololu openIMU software. Be warned version two of the board works much better than version one. I have fixed some bugs in the razor version. Included is the calibration of the magnetometer.

The biggest part of this post is to announce that the general library has been finished. It will work with either a 6 or 9 degree of freedom (DOF) system. To use make sure that your coordinate is in the North East Down convention. The accelerometer must be measuring gravity as positive along the positive direction of the axes. As far as I know all MEMs accelerometers will need to have the sign negated for each axis to meet this criteria. The gyroscope measurements must be in radians per second. Included in the software is a calibration sketch for the compass. Skipping this calibration will almost certainly make the yaw measurement incorrect. Further than that if the complete soft and hard iron compensation procedure is used the results will be optimal. As they say in the text books that will be left as an exercise for the reader since it is not absolutely necessary for the filter to work properly. Coming soon will be an altimeter that runs off of a simple two state Kalman filter fusing the accelerometer and a barometer as well as more complete documentation. I attempted to make the example for the openIMU clear and easy to understand.




If anyone uses this on a different IMU board please post the code and I will include it in the examples. Also, thank you to the early adopters of this IMU port.

(I am trying again to make this post.)

The essential question is if a port to ArduIMU hardware is planned or available? http://store.diydrones.com/ArduIMU_V3_p/kt-arduimu-30.htm

The drivers for the sensors are available at DIYDrones and FreeIMU.

I have had both the DIYDrones and FreeIMU firmware running on this platform and the former is problematic, in general, and FreeIMU works but has a lot of Yaw drift even after calibration. Some movies of these problems can be found here:

I am hoping openIMU firmware works better than the other firmware I have been testing.

I am planning a port of that board. But that is on my back burner. Currently I am doing board design. I am going to sell a break out board for the IMU, a MEGA shield for the openCopter flight controller, and an all in one unit for the flight controller. It will also be porting multiWii and arduPilot to work with my hardware. My software auto-detects whether you are using SBUS, DSM2 or DSMx serial, or standard RC signals. But I digress. Here is why freeIMU, arduIMU, sparkfun razor IMU etc have so much trouble with yaw. Look at the datasheet for that compass:


Notice that it says nothing about layout considerations. Now look at this version on the bottom of page 5


They specifically say to not put any pour under that IC. All those people do that. I doubt that even full soft and hard iron calibration would take care of those problems. I also consider it to be lazy design to not have all of the axes point in the same direction for the chips. Please don't get me wrong I think very highly of everything 3DR ardupilot and freeIMU. They have done awesome work. That was just the one nitpicky thing I noticed.

Not to mention that there are tons of fields around which really mess with compasses. My boards will not have that defect. Also, my boards employ 2 3.3v regulators. One for the 3.3v IO and another for the 3.3v analog inputs to the ICs. This hopefully will mean that my boards will significantly outperform the other guys boards.

If you want to do a sketch using the openIMU on that board I will be happy to offer you any guidance needed and include your code in the code examples. Good luck. Keep me posted.

Thanks... I suspected a hardware issue with both of the boards and even have large number of FreeIMU boards which I added to some panels of PCBs I originally did for another project. My plan was to build them up and see how it differed from the ArduIMU. I just checked the FreeIMU layout and you are correct that there is copper on the back side of the board under the compass. I don't think I will pursue either of these boards right now.

Are you doing anything in your software that isn't being done in either the ArduIMU or FreeIMU software that would improve on the performance, namely yaw drift/accuracy. BTW, I don't really care about roll or pitch in my application and, in fact, hope to fuse GPS heading data into the calculations at some point. My application is described here: http://freeimu.varesano.net/node/47.

When will your IMU board be ready? I do a significant amount of embedded design including layout, build, and test. I am happy to help out/collaborate in that regard with your new designs if you wish.

The breakout board is on its way back from China right now. I'll have to solder the components on etc. This first one is just a very limited run. Hopefully there will be much better performance from the compass. The algorithm I'm using works quite well for yaw. The problem is if north is skewed by a field it points to where the compass then thinks north is. I have tested it along side a regular compass and the results matched. You might compare the output of the freeIMU to that of an actual compass and see how the results match / vary.

mikesbaker, Will your new IMU board contain an on-board processor (like ArduIMU)? What sensors will be used? On-board wireless (bluetooth)?

I would be freaking delighted if this yaw drift problem everyone seems to have could be improved. I've got my fingers crossed.

BTW, GREAT work you've been doing.


Thanks for the compliment!

Hopefully my board will fix the yaw problems people have. Of course only so much can be done in the presence of a strong magnetic field. Those deflect north. On my tests I have very little yaw drift. Hopefully my boards will fix the problem entirely. I'm anxiously awaiting them.

Have you checked out openCopter in my github?


As it stands right now I will have three boards. All of the boards will have the gyro and acc on the SPI bus. The first will be a basic break out for the sensors. The next two will be most of what is required for openCopter. The GPS and telemetry radios will have to connect to the uarts. No built in bluetooth. The mega shield will have the sensors as well as all of the required pins for esc / servo control. It will also have SBUS, dsmx and dsm2 ports, as well as standard RC. The final one will be an all in one flight controller. The sensors will be the L3GD20 gyro, ADXL345 accelerometer, HMC5883L compass, and BMP085 barometer. Hope that answers your questions about the board. I am typing this from cell phone so I am sorry if this is not clear. I have had excellent results so far with you. Let's hope that the new boards provide even better results. Keep an eye on this thread. I will post as soon as I have the boards assembled.

Thanks again for the interest.

Any updates on this project? I've tried the MinIMU but I would love to have that yaw problem corrected. In your boards work I'll be wanting to order quite a few.

Hey Guys, :) I am now 12 and trying to make a nano quad . I thought that a gyro would be fit for stablizing it . But i don't know a bit for I2C protocol programming in IDE. Can any body give me a short program/sketch for reading gyro sensor value in which the 90 degree yaw and pitch reads normal or 0. Please a short sketch for reading value only using I2C. Please post it . I live in India =( =( =( =( :0

Thanks in advance.