/*
The Pololu MinIMU-9 v3 is a compact inertial measurement unit (IMU) that combines a 3-axis gyroscope, 3-axis accelerometer, and 3-axis magnetometer. This module uses the L3GD20H gyroscope, the LSM303D accelerometer/magnetometer, and communicates over I2C. Here's an example using the LSM303 and L3GD20 libraries with an Arduino:
Install the required libraries:
LSM303: https://github.com/pololu/lsm303-arduino
L3GD20: https://github.com/pololu/L3G-arduino
Upload the following code to your Arduino board:
This code initializes the LSM303D accelerometer/magnetometer and L3GD20H gyroscope, reads their data, and prints the values to the Serial monitor. Connect the MinIMU-9 v3's SDA, SCL, VCC, and GND pins to the corresponding pins on your Arduino board.
*/
#include <Wire.h>
#include <LSM303.h>
#include <L3G.h>
LSM303 compass;
L3G gyro;
void setup() {
Serial.begin(9600);
Wire.begin();
// Initialize the compass (accelerometer and magnetometer)
if (!compass.init()) {
Serial.println("Failed to detect and initialize compass!");
while (1);
}
compass.enableDefault();
// Initialize the gyroscope
if (!gyro.init()) {
Serial.println("Failed to detect and initialize gyro!");
while (1);
}
gyro.enableDefault();
}
void loop() {
// Read the accelerometer and magnetometer
compass.read();
// Read the gyroscope
gyro.read();
// Print the accelerometer data
Serial.print("Accel (X, Y, Z): ");
Serial.print(compass.a.x); Serial.print(", ");
Serial.print(compass.a.y); Serial.print(", ");
Serial.println(compass.a.z);
// Print the magnetometer data
Serial.print("Mag (X, Y, Z): ");
Serial.print(compass.m.x); Serial.print(", ");
Serial.print(compass.m.y); Serial.print(", ");
Serial.println(compass.m.z);
// Print the gyroscope data
Serial.print("Gyro (X, Y, Z): ");
Serial.print(gyro.g.x); Serial.print(", ");
Serial.print(gyro.g.y); Serial.print(", ");
Serial.println(gyro.g.z);
Serial.println();
delay(500);
}