Pololu MinIMU-9 + Arduino AHRS (Attitude and Heading Reference System)
Release Date: 2012-07-06
MinIMU-9-Arduino-AHRS provides a program (sketch) for the Arduino that interfaces with the Pololu MinIMU-9 inertial measurement units:
- MinIMU-9 v2 L3GD20 and LSM303DLHC carrier
- MinIMU-9 L3G4200D and LSM303DLM carrier
- MinIMU-9 L3G4200D and LSM303DLH carrier (discontinued)
A Python test program is also included. It communicates with the Arduino serially and displays a 3D representation of the MinIMU-9 board, allowing you to visualize the output of the AHRS in real time.
Both the Arduino software and Python test program are based on sf9domahrs by Doug Weibel and Jose Julio, which is in turn based on ArduIMU v1.5 by Jordi Munoz, William Premerlani, Jose Julio, and Doug Weibel.
The Python test program also has several dependencies you must install before you can run it:
- Python 2.6 or 2.7 (download the 32-bit version)
- pywin32 (again, download the 32-bit version)
After you have set up the prerequisites, download the archive from GitHub and decompress it.
Make the following connections with wires between the Arduino and the MinIMU-9:
Arduino Uno/Duemilanove MinIMU-9 5V -> VIN GND -> GND Analog Pin 5 -> SCL Analog Pin 4 -> SDA
Arduino Mega MinIMU-9 5V -> VIN GND -> GND Digital Pin 21 -> SCL Digital Pin 20 -> SDA
Using the AHRS
From the Arduino environment, open MinIMU9AHRS.ino, which can be found in the MinIMU9AHRS folder.
By default, the Arduino code treats the positive X axis of the MinIMU-9 as forward and the negative Z axis as up (so that the components are on the bottom of the board and the silkscreen is on top). If you want the positive Z axis to be up instead (so that the components are on top), find the definition of
SENSOR_SIGN at the beginning of MinIMU9AHRS.ino and uncomment the appropriate line (after commenting the original).
To ensure that the heading derived from the compass is accurate, you should change the
M_Z_MAX calibration constants to appropriate values. You can use the Calibrate example from the LSM303 library to find the right values for your board.
In the Tools menu, select the appropriate board and serial port. Click the “Upload” button to compile the sketch and load it onto your Arduino.
When the AHRS program first starts running, it takes some readings to establish a baseline orientation, during which it expects both the roll and the pitch of the sensors to be zero. Therefore, it is important to keep the MinIMU-9 level for a few seconds after powering on or resetting the Arduino or connecting to it from a computer.
After performing the startup routine, the program constantly takes readings from the gyro, accelerometer, and magnetometer on the MinIMU-9 and calculates an estimate of the board’s orientation. It outputs estimated roll, pitch, and yaw angles (in degrees) through the Arduino’s serial interface, and you can view the output with the Arduino Serial Monitor.
!ANG:0.08,0.09,137.01 !ANG:0.14,0.11,137.04 !ANG:0.15,0.12,137.06
To visualize the output of the AHRS, you can run the Python test program (MinIMU-9-test.py) while the Arduino is connected to your computer. (You will probably have to edit the file first and change the definition of
ser to match the COM port your Arduino is using.) You should be able to see three indicators showing the roll, pitch, and yaw angles being calculated by the AHRS, as well as a 3D representation of the MinIMU-9 board (the arrow indicates the positive X direction). You can watch these change in real time as you move the board around.
- 1.2.0 (2012-07-06): Added support for MinIMU-9 v2 (L3GD20 and LSM303DLHC); L3G4200D library dependency changed to L3G.
- 1.1.0 (2011-11-15): Added support for LSM303DLM; LSM303DLH library dependency changed to LSM303.
- 1.0.0 (2011-09-26): Original release.