SparkFun 9DOF Razor IMU w/AHRS

This notebook page deals with connecting the SparkFun 9 degrees of freedom [DOF] Razor Inertial Measurement Unit [IMU] to the mbed.

The 9DOF Razor IMU has a single-axis yaw gyroscope, a dual-axis pitch/roll gyroscope, triple-axis accelerometer and triple-axis magnetometer. It contains an ATMega328 to process these sensors and outputs their values over a serial interface.

Using this attitude heading reference system the sensor data can be fused to provide very reliable heading information.

Programming the IMU

The board comes with default test firmware on it and must be programmed with the AHRS to take full advantage of the sensors. If you don't have an AVR programmer to hand, you can always program it using your mbed:

AVR910: In-System Programming using mbed


mbed      razor
GND   --    GND
VOUT  --   3.3V
p9    --    RXI
p10   --    TXO


 * Read the yaw value from the SparkFun 9DOF Razor IMU.

#include "dof9RazorImuAhrs.h"
#include "mbed.h"

Serial pc(USBTX, USBRX);
dof9RazorImuAhrs theRazor(p9, p10);

int main() {
    while(1) {
        pc.printf("Yaw: %f\n", theRazor.getYaw());    

The AHRS program on the ATMega328 continually spits out heading and sensor data over the serial interface; a call to update() refreshes all the values wrapped in the dof9RazorImuAhrs class which are accessible by getter methods.

The full range of headings and sensors available are:

By default, the AHRS code is set to only print the heading data [roll, pitch, yaw]; in order to access the other sensors, the AHRS code will need to be recompiled with the PRINT_ANALOGS #define set to 1 and programmed onto the ATMega328. The same #defines are used in the dof9RazorImuAhrs class to determine what data you are expecting to read.


SparkFun 9DOF Razor IMU -
AHRS for SparkFun's "9DOF Razor IMU" -


Please log in to post a comment.