HAL Library 36- AHRS and IMU algorithms for calculating roll, pitch and yaw axes

With this library, it is possible to calculate roll, pitch and yaw axes from 2 or 3 sensors.

By using 2 sensors (Gyro and Accelerometer) you can use IMU or by adding Magnetic sensor, you can use AHRS algorithm to additionally stabilize outputs.

Library is written in ANSI C and works on any device you want. It is not specifically set to be used by STM32 devices.

Algorithms are developed by Sebastian Madgwick. For more info about these algorithms, you should check his website.


Read more about HAL libraries


  • Supports multiple independant calculations for multiple sensors if required
  • Calculates roll, pitch and yaw values from motion sensors
  • It uses 2 or 3 sensors each with 3 axes


  • Platform inpendent library written in ANSI C

Functions and enumerations

Functions and its enumerations can be found on AHRS IMU library API.


Conceptual use is available on my Github account.

TM STM32 Libraries

STM32 libraries based on STM32Fxxx HAL drivers.


Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!