Orientation Test (USB)

The Adafruit_AHRS repository contains everything you need to run a sensor fusion algorithm and get orientation data out of the NXP Precision 9DoF Breakout.

Generating Orientation Data

Before you can view or work with orientation, you first need to run the raw sensor output through something called a sensor fusion algorithm. As the name implies, this takes the output from a variety of sensors, and merges the results into orientation output, typically in Euler angles or Quaternions.

To generate orientation data, load the ahs_fusion_usb sketch (code on Github) in the Arduino IDE:

With this sketch loaded, make sure that you are targeting the right set of sensors, since this sketch can be used with a variety of different sensor models.

Make sure that you have selected NXP_FXOS8700_FXAS21002 as the AHRS_VARIANT macro:

Download: file
// Define your target sensor(s) here based on the list above!
// #define AHRS_VARIANT    ST_LSM303DLHC_L3GD20
#define AHRS_VARIANT   NXP_FXOS8700_FXAS21002

Compiling your sketch should produce output similar to this, though the final file size will vary depending on the platform you are compiled against:

You can test the output of this sketch by opening the Serial Monitor, where you should see some orientation output in Euler Angles by default:

Visualizing the Orientation Data

Next, you can visualize the orientation data if you want using an optional Processing sketch called bunnyrotate_ahrs_fusion_usb.pde (source on Github).

You can find the Processing sketch in ~/Documents/Arduino/libraries/Adafruit_AHRS/processing or you can click here to download the entire zip and extract the subdirectory

With the ahrs_fusion_usb sketch running in the background, as describe in the section above, open the bunnyrotate_ahrs_fusion_usb sketch in Processing, and run it.

Make sure that the Arduino Serial Monitor is closed before running the Processing app, or the serial port that provides the orientation data won't be available to Processing!

When you run the sketch, you will see a window pop up with a drop down box on the top section where you can select a serial port.

Select the serial port generated by your development board, and the Processing sketch should start capturing incoming aw orientation data. As the orientation data changes, the bunny on the screen will rotate along with the NXP Precision 9DoF Breakout:

As you rotate the board, the bunny should follow the movement similar to the .gif below:

This guide was first published on Apr 14, 2017. It was last updated on Apr 14, 2017. This page (Orientation Test (USB)) was last updated on Sep 17, 2019.