A libre breakout board for the Invensense MPU6050

Last updated on Sat, 2011-10-15 13:18. Originally submitted by fabio on 2011-01-20 11:04.

I just finished designing a breakout board for the upcoming Invensense MPU6050. The chip has a gyroscope and a accelerometer and it's capable of polling data from a third party magnetometer (or any other i2c device).

On the various press launches about this chip you might read that it does sensor fusion on chip.. personally, I'm still skeptical about that as the same has been told about the IMU3000 but so far nothing about that is described on the IMU3000 datasheet.

A comment on Sparkfun's Digital IMU breakout of the IMU300, by Hypernova, perfectly describe my feelings:

Executing a program for X seconds then killing it: a simple bash script

Last updated on Thu, 2011-01-20 14:16. Originally submitted by fabio on 2011-01-10 17:50.

I needed to execute a given command for a specified number of seconds on my Linux system. I wasn't able to find a program for doing that so I ended up writing this little and simple Bash script:



echo "Executing: ${cmd} for $seconds seconds"

sleep $seconds

if [ -d /proc/$cmdpid ]
  echo "terminating program PID:$cmdpid"
  kill $cmdpid

If you save this into a file called run_seconds_then_exits.sh you use it with:

bash run_seconds_then_exits.sh "sleep 10" 5

The above will run the command sleep 10 for 5 seconds, then it will send a termination signal (SIGTERM) and the program will be terminated.

See any improvements to the script above? Please leave a comment below and let me know about it!

Posted in:

An I2C logic level converter/translator with integrated voltage regulator

Last updated on Mon, 2011-04-04 16:55. Originally submitted by fabio on 2011-01-07 13:20.

When using I2C to interface devices operating at different voltages, for example an Arduino running at 5 Volts and a sensor running at 3.3 Volts, it's usually a best practice to use a logic level converter/translator to translate one logic signal from one voltage to the other and vice versa.

There are devices which will work without problems even without a logic level converter (for example I used the ADXL345, the ITG3200 and the HMC5843 without it) but once you want to get very good precision it may be worth using a logic level converter. Moreover there are many devices which could get damaged if used without one.

FreeIMU's stancils have arrived

Submitted by fabio on Wed, 2010-12-29 18:51.

I just get back home and I found FreeIMU's stencils in the mail.

FreeIMU Stencil

I ordered these stencil from http://www.smtstencil.co.uk/ . I still did not used the stencil, I'm still waiting for the PCBs, but I think they are pretty good quality. Even the smallest pads on the PCB design have been reproduced perfectly.

Looking forward put some paste on them!

Posted in:

Femtoduino: designing an ultrasmall arduino compatible board with the ATMEGA 328P QFN/MLF32

Last updated on Wed, 2011-02-16 12:22. Originally submitted by fabio on 2010-12-29 15:45.

UPDATE 2011-02-16: Femtoduino has now its own project page where you will find all the design sources and all the informations on it.

As a personal learning exercise and challenge to myself, I designed an ultrasmall Arduino compatible board based on the ATMEGA 328P in the QFN/MLF32 package.

Using the smallest 328P uC currently available, very small package components (eg 0402 caps and resistors) and 0.05" headers I've been able to design an Arduino compatible board which is only 20.7x15.2 mm.

Given that the Arduino Pro Mini, currently the smallest Arduino board available, is 34x18 mm and I restricted myself to use a 2 side PCB, I think I accomplished a pretty good result.

I called this board Femtoduino. Have a look at the schematics. Of course this will be a free (as in speech) hardware.

Femtoduino PCB desing

I plan to submit this board to the DorkbotPDX group PCB order of the 3rd January and I'm currently looking for reviews for the project. So, if you have knowledge of this topics please have a look at the Femtoduino designs.

You can get the Kicad sources (as of 30-12-2010) from the attachments below. I'm using a weekly updated version of Kicad, so if you have problems with older versions of Kicad you can try use a recent snapshot for Windows or Ubuntu 10.10.

You can get the most updated sources from my personal repository using bzr with the following command:

bzr co http://repository.varesano.net/Femtoduino

Thanks for your help!

UPDATE 2011-01-28:

I've been able to reflow solder femtoduino and all it's components, including 0402 capacitors! See a picture of Femtoduino!

UPDATE 2011-01-29:

Femtoduino is alive!

FreeIMU: designing a free (as in speech) 9 DOM/DOF MARG IMU

Last updated on Wed, 2011-05-25 08:38. Originally submitted by fabio on 2010-12-09 10:53.

UPDATE 2011-02-10: Check out FreeIMU project page for all the informations about FreeIMU!

In the past months I worked a lot on accelerometers, gyroscopes and digital compasses. I'm now pretty intimate with the ADXL345, the ITG3200 and the HMC5843.

I've been able to design and construct homebrew DIY breakout board PCBs for all of them (ADXL345 and ITG3200) and to create a nice library to use them which also implement a great sensor fusion algorithm capable of running on the Arduino without problems.

I'm now making the next step. Let me introduce FreeIMU.


FreeIMU is a 9 DOM/DOF MARG IMU based on the ADXL345, the ITG3200 and the HMC5843. As this is part of my Master of Science Project and that I completely share the openness of projects like Arduino, FreeIMU will be completely open: all the designs will be released under a Creative Commons Attribution-ShareAlike 3.0 Unported while all the software will be release under GNU GPL v3.

As my background is in computer science, I'm quite self-taught in PCB designs and in electronics in general. So, I'm now seeking review for FreeIMU's schematics and PCB designs. If you have experience working with IMUs, designing PCBs or circuits and you would like to contribute to a free project please have a look at the designs and feel free to comment it.

I'm using kicad as schematics and PCB editing software. It's free (as in speech) software and, once you get around its glitches, it works really well. Using non-libre software like EAGLE to design a free hardware like FreeIMU would have been simply senseless.
Note: I'm using a nightly updated version of Kicad, so if you have problems opening the files you might need to update your version of Kicad.

So, you'll find the current Kicad based sources of FreeIMU in the attachments to this page just below. You'll also need a library of components which I also attach here. For your convenience I attach also a pdf version of the schematics.

I plan to submit FreeIMU to DorkbotPDX PCB Order of the 13th December to have it constructed. I currently don't see this as a commercial project but if someone is interested in FreeIMU I could sell a couple of boards.

Ok, so.. looking forward to hear your comments. Thanks!

UPDATE 2010-12-13:

FreeIMU designs have been sent for fabrications. Looking forward to receive the PCBs soon! I have received some interesting advices on the board design so the design sent to production has been slightly modified: there's now space for an optional 10uF tantalum capacitor in package A and there's more clearance for the mounting holes. The original design would have been making almost impossible screw FreeIMU as there were some capacitor just near the mounting holes.

You find the final PCB design in the attachments below. I also attach below the Gerber and drill files sent for production.

I'd like to thanks everyone who helped in reviewing and advising on FreeIMU. I'd like to thank especially Greg Peek from dorkbotpdf-bladder mailing list who convinced me on adding the 10uF cap and adding more clearance on the mounting holes. I'd like also to thank James Neal for suggesting the addition of the mounting holes in the first place and for taking care of organizing the PCB group order.

UPDATE 2010-12-22:

The FreeIMU project is progressing nicely.

Yesterday Laen received FreeIMU's PCBs and they shuold have been
shipped to me today.

I've also been able to find cheap stencils from
http://www.smtstencil.co.uk/ .. They should have shipped the stencils

Meanwhile I ordered all the components to produce 10 copies of FreeIMU.

The code is now quite stable and I'm using it on my tangible user
interface prototype (basically it's a sphere capable of detecting
taps, double taps and its orientation - more on this on my blog soon).

I should be able to produce the first boards around the first week of
January.. I'm really looking forward to it!

UPDATE 2011-01-02:

The interest this project is getting is huge! Thanks to everybody who contacted me about FreeIMU and to the people who already reserved FreeIMU units.

For those who are interested in buying one or more FreeIMU units here are the prices:

  • Fully assembled FreeIMU v0.1: 80 euro 70 euro with international shipping and pre-soldered female or male headers (at your choice) included. For multiple orders I can offer a discount, just get in touch with me.
  • FreeIMU v0.1 raw PCB: 15 euro with international shipping included and non-soldered female or male headers. Note: You will have to buy the ICs sensors by yourself and be able to reflow solder them.

If you want to buy one or more units please get in touch with me and I'll reserve your units for you. The number of available units is limited and a strict first came first served policy will be followed so reserve your units as soon as you can to be sure to get one.

UPDATE 2011-01-14:

Still no signs of FreeIMU's PCBs. It looks like Lean will need a better shipping option for us in Europe. More than 3 weeks already passed from the shipping of the PCBs from the USA to Italy and still no signs of them. Of course, we had the holidays in the middle, but that's way too much!

UPDATE 2011-01-18:

Just created a FreeIMU project page on Launchpad. Using launchpad for FreeIMU development will give us some great advantages like: an high quality repository with bazaar, code and designs browsing, questions and answers, bug and features suggestions.. Moving the project to a public place was a step to be made.

So, from now on, you can download FreeIMU designs from it's repository using:

bzr co lp:freeimu

UPDATE 2011-01-20:

Still no signs of FreeIMU v0.1 .. fuc**in Italian customs. Anyway, FreeIMU version 0.2 has been sent for fabrication and today it has been shipped to me. This time of course using FedEX which shouldn't be so slow as regular mail. Let's hope so..

Following some picture of FreeIMU v0.2:
FreeIMU v0.2 top view

FreeIMU v0.2 bottom view

UPDATE 2011-01-26:

FreeIMU is alive! First units of FreeIMU have been produced and I'm currently testing everything. Stay tuned!

Initial implementation of a 9 DOM/DOF MARG IMU orientation filter with ADXL345, ITG3200 and HMC5843 on Arduino

Last updated on Tue, 2011-05-10 13:49. Originally submitted by fabio on 2010-12-04 16:15.

UPDATE 2011-05-10: The 9 DOM sensor fusion library presented in this article is now part of the FreeIMU library. Please consider the code in this page as outdated and just use the FreeIMU library.

I spent the last days creating an initial implementation of a 9 Degrees of Measurement (DOM) / Degrees of Freedom (DOF) AHRS sensor fusion orientation filter. I've created a library, called FreeIMU, which polls data from the ADXL345 accelerometer, the ITG3200 gyroscope and the HMC5843. Have a look at the attachments for my circuit schematics.

To access the ADXL345 accelerometer I used this nice Arduino library (based on this other one), while for the ITG3200 I used Filipe Vieira's ITG3200 Arduino library. To access the HMC5843 I used my library.

The sensor values are then pushed into Sebastian Madgwick's implementation of Mayhony's DCM filter incorporating Sebastian's magnetic distortion compensation (Algorithm available here - project here).

IMPORTANT: This code doesn't disable the ATMEGA internal pullups so a logic level converter/translator is needed if you don't want to fry your sensors. In the video I used a modified version of twi.c (inside of the Wire library) commenting out the pullup enabling in twi_init().

The result can be seen in the video below. Note that all the code published here is still very very young. You'll probably find lots of bugs and WTF but I think it can still be useful. Keep an eye on this website for the next developments. If you are working on this stuff get in touch with me if you want to share efforts.

An HMC5843 magnetometer library for Arduino based on Wire

Last updated on Fri, 2012-07-27 16:32. Originally submitted by fabio on 2010-12-01 13:22.

UPDATE 2012-07-27:

The HMC58X3 library is now part of the FreeIMU library. Please refer to the FreeIMU library page for newer code.

UPDATE 2011-01-22:

I moved the development of the HMC5843 Arduino library to Launchpad. This way we will have a proper repository, bug tracking, question/answer, etc.. You can find it here: A libre Arduino Library for the HMC5843 and HMC5883 Honeywell magnetometers

I just completed porting the HMC5843 Arduino library, originally created by Nirav Patel (his library) and then extended/improved by E.J.Muller (his library), to use only the Arduino Wire library to use the I2C bus.

First steps with the HMC5843 with Arduino: verify the accuracy of its results

Last updated on Mon, 2010-11-29 20:22. Originally submitted by fabio on 2010-11-24 14:04.

I finally got an HMC5843 magnetometer breakout board. I wasn't able to make a DIY breakout board for this chip (but I'm still willing to try that again) so I had to buy one. Of course I ended up with one made by Sparkfun sold by watterott.com.

HMC5843 breakout board from sparkfun

So now I'm moving my first steps with this chip. I'm now verifying the accuracy of its readings. I found a nice Arduino library on Arduino forum which contains a calibration routine (there is a copy in the attachments below). It looks like it simply uses an internal calibration feature. I'm still not sure on how this actually works.

However I ended up plotting some graphs from the readings from the chip while rotating it around the Z axis and while moving it in 3d rotations. Ideally, in a perfectly calibrated device these graphs should be respectively a circle and a sphere centered in the origin.

These are the resulting pictures:

X and Y readings rotating the HMC5843 around the Z axis:
X and Y readings rotating the HMC5843 around the Z axis

X, Z and Y readings rotating the HMC5843 in 3D:
X, Z and Y readings rotating the HMC5843 in 3D

As you can see the picture are not perfect circle and spheres so a more complex calibration routine its probably needed to get very precise readings.

I still don't know if the precision I'm currently getting would be enough or not for my needs. I asked for clarification on a Sparkfun forum thread on the topic but I still didn't got a reply.

Thanks to newbee on Arduino forum I found this nice paper by ST Microelectronics called Using LSM303DLH for a tilt compensated electronic compass which describe quite well a procedure to calibrate a magnetometer (it actually covers tilt compensating a magnetometer with an accelerometer, so it might came handy in further developments).

I attach here the gnuplot "programs" I implemented to create the above graphs. If you are working with the HMC5843 they may come useful.

makeplot3d.p reads data from a datafile. It expects data to be comma separated in the X,Y,Z form

makeplot.p instead expect a datafile with space as separator.

I created the dumps of the readings using the attached test_serial.py_.txt python script. You will need PySerial installed on your system to use it.

Save it, rename it to test_serial.py then simply run python test_serial.py > dump.txt so you will have all the values coming from the Arduino in the dump.txt file ready to be used by gnuplot.

EDIT: On Sparkfun forum user pvmellor asked what typical variance and standard deviations we get from the HMC5843. So, I created a simple octave (matlab) script to compute the std and variance from a csv file containing (not so) calibrated readings from the HMC5843 (see above).

My results, of a 3 minutes dump (HMC5843_steady.data) of the readings coming from the Arduino code _11_hmc5843_calibrazione.tar_.gz while keeping the device steady, computed with the Octave script HMC5843_statistics.m were (X Y Z):


    8.8842    5.5359   15.1949


    78.929    30.646   230.885

My first 6 DOF IMU Sensors Fusion Implementation: ADXL345, ITG3200, Arduino and Processing

Last updated on Mon, 2012-07-23 09:09. Originally submitted by fabio on 2010-11-22 21:36.

When you have created two breakout boards for the ADXL345 accelerometer and the ITG3200 gyroscope and you have those two nice sensors what you can do? Simple: create an implementation of an Attitude sensor fusion which runs with those chips!

So, I started documenting myself and reading lot of stuff on IMUs (inertial measurement units - composed by an accelerometer and a gyroscope) and MARG sensor (an IMU which also has a magnetometer to sense heading).

One really good article you should read to get started with IMUs is A Guide To using IMU (Accelerometer and Gyroscope Devices) in Embedded Applications available on http://www.starlino.com/ . Also from the same website there is a nice implementation of the theory from the IMU guide: you can find it on Arduino code for simplified Kalman filter. Using a 5DOF IMU.

So, I took the algorithm above and converted it to be used with the ADXL345 and the ITG3200. I came out with two implementations both with parts in Arduino and Processing code (see the attachments to this page below).

IMPORTANT: If you use the IMU Digital Combo Board from Sparkfun you will need to change the address of the Gyroscope from 0x69 in my code to 0x68.

The first implementation simply reads the raw accelerometer and gyroscope values on the Arduino while the Processing code (running on the PC) will compute the sensor fusion algorithm, produce the orientation vector and siplay a nicely oriented cube.

In other implementation all the sensor fusion logic is implemented in Arduino code so it will run embedded in the microcontroller. Looks like Arduino can coupe with that without any problems! So, once the orientation is computed is all sent to the PC where the Processing application will display incoming data and the oriented cube.

You can see a demonstration in the following video:

All the code is available in the attachments below. You can see the circuit in the picture below. Note that these are custom made breakout boards, your pin configurations will vary depending on the schematics of your breakout board. If you have questions just leave a comment below.

The processing programs need to be executed on the Processing IDE, available for download from http://processing.org/
Remember to adjust the serial port configuration in the Processing code to match your connection to the Arduino in your system. Here I use /dev/ttyUSB9, if you are under windows you'll probably have to use something like COM3 or something like that. See in the Arduino IDE under Tools->Serial Port to get the exact value you have to use.