Reefwing AHRS Arduino Library for Drones — Part 2

David Such
12 min readAug 9, 2023

The Reefwing AHRS library provides an Attitude and Heading Reference System (AHRS) class for use with Arduino compatible boards. In Part 2 of this article we will explain how to use the library and provide hardware specific examples for the Arduino Nano, Nano 33 BLE, Nano 33 BLE SENSE (REV 1 and REV 2), Nano 33 IoT, MKR Vidor 4000, Portenta H7 and the Seeed XIAO nRF52840 Sense boards. These will use the following IMUs:

  • LSM9DS1
  • LSM6DS3
  • BMI270 & BMM150
  • MPU6000/MPU6500/MPU6050

Using the Reefwing AHRS Library

In order to get the correct angles out of the AHRS, we need to take the following steps:

  1. Calibrate the IMU (if available) and assign the appropriate offsets. This is normally possible in the IMU library.
  2. In setup(), instantiate the ReefwingAHRS class and call begin() to detect the board type, and assign the default free parameters, fusion algorithm (Madgwick) and declination (Sydney, Australia). If you want to use something other than the defaults, then change those now.
  3. On each iteration of loop():
  • If required adjust the sensor data to the correct format. Accelerometer — g, Gyroscope — DPS (degrees per second), and Magnetometer — can be anything (e.g., gauss or uT). The other thing to check is that the axis orientation is consistent for the three sensors. On the LSM9DS1, the…

--

--

David Such

Reefwing Software · Embedded Systems Engineer · iOS & AI Development · Robotics · Drones · Arduino · Raspberry Pi · Flight Control