MS5611-01BA Arduino library: first developments results

Last updated on Sun, 2012-09-09 18:08. Originally submitted by fabio on 2011-06-12 20:16.

I spent the last days working on the MS5611-01BA high resolution pressure sensor. I wrote an Arduino library for it which you can find on my bzr repository:

  • browse repository
  • download library
  • use bzr co to get a copy directly using bzr.
  • the MS5611 library is now part of the FreeIMU library. Please refer to the FreeIMU library for newer code.

The library comes associated with a Processing visualization sketch which you can use to visualize a the readings coming from the sensor using a graphical tool.

The results I've got so fare are pretty good. Precision is about 0.02-0.03 mbar and altitude estimation resolution is about 10-15 cm. Relative measurement of altitude using the sensor looks very good but I'm still looking for a better approach on absolute altitude estimation.

In the video below you find an example of my initial developments.

From the AHRS sensor fusion orientation filter to a 3d graphical rotating cube

Submitted by fabio on Fri, 2011-01-28 12:52.

In a comment from Ciskje on my sensor fusion implementation, I've been asked to explain how the Processing graphical uses rotations to visualize the orientation informations coming from the sensor fusion algorithm.

The question was basically, what's the reason about using the Yaw, Pitch and Roll in a "strange" order in the following lines of code in my Processing graphical cube example:

rotateZ(-Euler[2]); // phi - roll
rotateX(-Euler[1]); // theta - pitch
rotateY(-Euler[0]); // psi - yaw

The following explanation assumes some basic knowledge of rotation matrices and 3d coordinate systems. For a good introduction on the topics, I strongly suggest reading Chapter 2 of "Robot Modeling and Control" by Mark W. Spong.


The first thing you have to understand is that we have 3 coordinate systems here.

  • OsXsYsZs attached to the sensor array
  • OwXwYwZw attached to the real world, with Xw pointing to the Hearth North and Zw pointing to the sky
  • OmXmYmZm the coordinate system of the graphics program, usually it is attached on the top left corner of the monitor with Xm pointing right, Ym pointing down and Zm pointing forward to the monitor.

Note that when Xw and Zm are aligned (you point the monitor to the Earth north in your location) there is a simple relationship between OwXwYwZw and OmXmYmZm: a point pw defined in the coordinate system W having coordinates pw = [pw_x, pw_y, pw_z] can be expressed in the coordinate system M doing pm = [-pw_y, -pw_z, pw_x]

The sensor fusion algorithm running on Arduino computes a quaternion representing the orientation of OsXsYsZs with respect to OwXwYwZw, and from the quaternionToEuler function in the Processing code we can get the Euler angles expressed in the aerospace sequence, so they are the yaw (ψ - psi), pitch (θ - theta) and roll (φ - phi) angles.

We can use them in the following way: supposing that OsXsYsZs and OwXwYwZw are aligned in the beginning we can rotate OsXsYsZs so that it would assume the orientation described in the quaternion or yaw, pitch, roll angles by:

  1. rotate by ψ around Zs
  2. rotate by θ around Ys
  3. rotate by φ around Xs

After doing the above we will obtain that OsXsYsZs is oriented with respect to OwXwYwZw according to the orientation described by the output quaternion from the sensor fusion algorithm.

The same result could have been produced by rotations relative to the W coordinate system, but using the reverse order:

  1. rotate by φ around Xw
  2. rotate by θ around Yw
  3. rotate by ψ around Zw

However, we are interested in rotating the graphical cube which is defined in the OmXmYmZm coordinate system so a slightly different approach is needed. From the relationship between OwXwYwZw and OmXmYmZm described above we can see that there is a relationship between the rotations made in the W and M coordinate system:

  • a rotation φ around Xw corresponds to a rotation of -φ around Zm
  • a rotation θ around Yw corresponds to a rotation of -θ around Xm
  • a rotation ψ around Zw corresponds to a rotation of -ψ around Ym

Given the above and remembering that in Processing the rotations are made in respect to the monitor frame we can conclude that, in order to align a graphical cube defined in the OmXmYmZm to the orientation described by the quaternion and then Euler angles coming from the sensor fusion algorithm of the sensors coordinate system OsXsYsZs, we have to do the following rotations:

  1. a rotation of -φ around Zm
  2. a rotation of -θ around Xm
  3. a rotation of -ψ around Ym

as we wanted to demonstrate.

Exploring the advanced features of the ADXL345 Accelerometer: single & double tap, activity, inactivity, free fall, power saving

Submitted by fabio on Mon, 2010-11-22 16:57.

I spent a couple of days playing with the advanced features of the ADXL345 accelerometer. These are all configurable in the various registers of the chip, is just a matter of studying a bit the specs and doing some tests.

I've been able to implement: power management (the chip goes to sleep after some amounts of inactivity for time and then start doing full measurements when it detects activity again) and the related activity and inactivity detection, per axis single and double tap detection as well as free fall detection.

The video below shows you what I have been able to accomplish. All the source codes are available in the attachments below and released under GNU GLP v3 license.

The code is pretty well documented and self explaining. In case you have a question feel free to leave a comment below.

A new homebrew DIY breakout board PCB for the ADXL345 accelerometer

Last updated on Sat, 2010-12-04 16:12. Originally submitted by fabio on 2010-11-22 16:12.

Some time ago I created my first homebrew breakout board PCB for an ADXL345 accelerometer. After getting more experienced and testing the whole procedure some times I created a new and improved version.

In the attachments below you find all the Kicad sources needed to edit the design or printing the design by yourself.

All the designs are released under the Creative Commons — Attribution-ShareAlike 3.0 Unported Licence.

To show you how this works I created a video description:

Sending float variables over Serial without loss of precision with Arduino and Processing or Python

Last updated on Tue, 2010-11-30 16:58. Originally submitted by fabio on 2010-11-19 15:42.

For a project I'm working on, I had the need to send some float variables computed on the Arduino board to a Processing program running on a computer over a Serial communication Link.

Arduino doesn't have any "out of the box" way to send float variables over the Serial interface but one could simply send approximations: send the float as an integer and truncate the decimals or send it only with two digit for the decimals.

Unfortunately, I needed the best precision for my project so the above solutions weren't actually useful.

An homebrew DIY breakout board for the ITG3200 gyroscope: tested with Arduino and Processing

Last updated on Tue, 2012-01-31 12:57. Originally submitted by fabio on 2010-11-08 16:21.

Some days ago I posted about my first homebrew DIY breakout board for the ADXL345 accelerometer. That was pretty ugly but worked very good.

Today, after some other tests, I show you my new homebrew DIY breakout board: this time it is for an ITG3200 gyroscope. And you'll see that I really improved a lot!

An homebrew DIY breakout board for the ADXL345 accelerometer: first process try. Tested with Arduino & Processing

Last updated on Mon, 2010-09-27 12:20. Originally submitted by fabio on 2010-09-25 18:37.

This is my first try in creating an homebrew DIY breakout board for the ADXL345 accelerometer.

Yes, I know: it's pretty ugly.. but it works! This is the first try.
I'll try again soon using all the things I understood this time!

This is how I did it:

  1. Design the PCB using Kicad
  2. Print the PCB tracks to an Press and Peel sheet
  3. Iron the Press and Peel sheet on a copper board
  4. Etch with Ferric Chloride
  5. Clean with Nitro Solvent
  6. Drill with 0.8mm drill bit
  7. Cook the PCB after placing the ADXL345 chip with Sn62 Solder Paste
  8. Solder capacitors and male headers to the PCB
  9. Wire the PCB to Arduino through a breadboard
  10. Use some Arduino and Processing programs to test the board. Source codes available here

I want to say thanks to:
Kicad developers for making such a great Free, Libre and Open Source PCB design software
Laurent Saint-Marcel for giving me some great Kicad ADXL345 footprints
The guy behind for providing a great Arduino and Processing ADXL345 tutorial

I'll probably write a more detailed how-to in the next days, meanwhile feel free to add a comment below.