Access the 9-Axis IMU on your PixieBoard

Roberto Himmelbauer
PixieBoard
Published in
4 min readAug 2, 2018

In this tutorial I will explain how simple it is to enable the 9-Axis IMU on your PixieBoard. You will see how you get readings from the Accelerometer, Magnetometer and Gyroscope.

Requirements

  1. Have an already configured PixieBoard. If you are just getting started with your PixieBoard I recommend you first follow this tutorial Getting Started With PixieBoard. If you do not have a PixieBoard you can get one here.
  2. Have internet connection on your PixieBoard to install packages.

FX0S8700 & FXAS2100X

The PixieBoard combines 2 of NXPs best motion sensors. The FXA2100X has a built in 3 axis Gyroscope and the FX0S8700 has a built in 3 axis Acelerometer and a 3 Axis Magnetometer.

I recommend you take a look at each of the sensors data sheets so you have a better understanding on some of the vaules we will be looking at to read each of the sensors data(FX0S8700 and FXAS2100X).

Also recommend you take a look at Adafruits comparision between differente motion sensors. If you are intrested in seeing how they compre to other senosors look at this tutorial.

Getting Started

Update your system! You should always run the lates version. Lets start by doing so:

sudo pacman -Syu
sudo reboot

Now that your PixieBoard is up to date. It is time to install 2 packages that will help us read and test if the motion sensors are activated.

Lets start with evtest:

sudo pacman -S evtest

evtest is a tool used to print the description of a kernel device. You can also use it to monitor other devices. You can find more information on the package here.

i2c-tool allows you to read I2C address values from the kernel. Lets install the package with:

sudo pacman -S i2c-tools

evtest

We can run evtest to see what device are available:

sudo evtest

Output:

evtest Output

Lets input 3(event3 FXAS2100X Gyroscope). You should see the following output:

Output

If the sensor would be active evtest would conintuesliy output the result of the sensors reading. Pres CTRL+C to exit the tool.

Enable the Sensors

Believe it or not but it only takes 3 lines to enable the 3 sensors. You only need to execute them as root:

sudo su
echo 1 > /sys/devices/virtual/misc/FreescaleAccelerometer/enable
echo 1 > /sys/devices/virtual/misc/FreescaleMagnetometer/enable
echo 1 > /sys/devices/virtual/misc/FreescaleGyroscope/enable
exit

Lets run again evtest to see if we can see the outputs of the sensor:

sudo evtest

Output may vary, select 3 for the Gyroscope:

Once you select the corresponding event you should see the following output:

If you move your PixieBoard around you will notice how the values change. You are probably thinking well how am I going to get all 9 individual values. Well that is where i2c-tools comes in.

i2c-tools

Lets start by listing all I2C buses:

sudo i2cdetect -l

Output:

We only have 1 I2C bus

We can see that we have 1 bus available, bus 1. Now we can see in which address the senesors are listed in the bus with:

sudo i2cdetect -y -q 1

The UU means that the sensors are already used by the kernel. If you look at the datasheet of each sensor you will see that the FX0S8700 values are located at address 0x1E while the values for FXAS2100x are in the address 0x20.

You can view all sensor value address with:

 i2cdump -f -y 1 0x20

Output:

The Gyroscope datasheet explains that the absolute values for the Gyroscope are located between address 0x01 and 0x06.

You can get specific address with the command:

sudo i2cget -f -y 1 0x20 0x01

Script Time

Lets write a simple script that will:

  1. Enable the sensors
  2. Output the absolute value of the sensors.

To create a shell script simply type:

sudo nano pixieboard_9_axis.sh

Clone this git repo:

sudo git clone https://github.com/pixierepo/pixieboard_9_axis.git
cd pixieboard_9_axis

Give the script execute permission with:

sudo chmod u+x pixieboard_9_axis.sh

To execute the shell script:

sudo ./pixieboard_9_axis.sh

Move your PixieBoard around to see the different values:

Hope you enjoyed the tutorial if you have any questions please let me know at roberto.himmelbauer@codeandmodules.com

--

--

Roberto Himmelbauer
PixieBoard

Engaged and interested in tackling problems related to IoT and Edge Solutions, Device Security and Software Provisioning