Thursday, February 3, 2011

MARG sensors + Bluetooth

MARG (Magnetic, Angular Rate, and Gravity) sensor array used for AHRS (Attitude and Heading Reference Systems).

Android OpenGL 3D display on Samsung Spica (i5700).

Sparkfun 9DOF sensor stick SEN-10389, later replaced by SEN-10321.

Using ATmega328P, operated at 3.3V supply and 8MHz crystal. At this speed, reading sensors' measurements and computing "AHRSupdate" take about 31ms to complete. Default compiler setting is used on WinAVR. With 25Hz sampling rate, this leaves mega328p extra 9ms to do other tasks. Bluetooth SPP (serial) communication is buffered and interrupt driven, so no processing time is wasted in reading and sending data to the android phone.

(1) Sebastian Madgwick's Alternative AHRS (MARG) algorithm - Quaternion implementation of Mayhony's DCM filter incorporating magnetic distortion compensation.
(2) Fabio Varesano's FreeIMU. Also using Madgwick's implementation of the DCM filter on Arduino platform.
(3) Rotation convertions by Martin Baker. Very good discussion on quaternions and other 3D representation like Euler angles and transformation matrix.
(4) OpenGL Transformation Matrix by Song Ho Ahn
(5) Similar discusion on started by Harinath

Android project examples:
Android Bluetooth
Bluetooth Chat
Android OpenGL Projects
OpenGL ES tutorial
Android Bluetooth Oscilloscope

Special thanks to the generous guy who gave me these toys, Thank you very much!


  1. Very Nice!
    What for Bluetooth Modul have you used?

  2. Anyone reading this that knows 'yus please ask him to contact Craig at or as I may have some work for him along the lines of his MARG project. So far has not answered his emails.