Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The Pololu MinIMU-9 v5 is a compact inertial measurement unit (IMU) that includes an LSM6DS33 3-axis gyro and 3-axis accelerometer and an LIS3MDL 3-axis magnetometer. The following example demonstrates how to use an Arduino to read the sensor values from the MinIMU-9 v5.
- First, you will need to install the "LSM6" and "LIS3MDL" libraries by Pololu. Open the Arduino IDE, navigate to "Tools" > "Manage Libraries..." and search for "LSM6" and "LIS3MDL" by Pololu. Install the libraries, and then restart the Arduino IDE.
- Next, connect the Pololu MinIMU-9 v5 to your Arduino as follows:
- Connect the IMU's VDD pin to the Arduino 3.3V pin.
- Connect the IMU's GND pin to the Arduino GND pin.
- Connect the IMU's SDA pin to the Arduino A4 pin (or SDA pin if using an Arduino board with dedicated SDA/SCL pins).
- Connect the IMU's SCL pin to the Arduino A5 pin (or SCL pin if using an Arduino board with dedicated SDA/SCL pins).
- Now, upload the following code to your Arduino:
- This code initializes the LSM6DS33 and LIS3MDL sensors using the Pololu libraries and reads the gyroscope, accelerometer, and magnetometer values in the loop(). The sensor values are then printed to the serial monitor every second.
- After uploading the code to your Arduino and opening the serial monitor, you should see the gyroscope, accelerometer, and magnetometer values being printed.
- You can modify the code to process the sensor values, implement sensor fusion algorithms, or control other devices based on the sensor readings according to your project requirements.
- */
- #include <Wire.h>
- #include <LSM6.h>
- #include <LIS3MDL.h>
- LSM6 imu;
- LIS3MDL compass;
- void setup() {
- Serial.begin(9600);
- Wire.begin();
- if (!imu.init()) {
- Serial.println("Failed to initialize LSM6DS33.");
- while (1);
- }
- imu.enableDefault();
- if (!compass.init()) {
- Serial.println("Failed to initialize LIS3MDL.");
- while (1);
- }
- compass.enableDefault();
- }
- void loop() {
- imu.read();
- compass.read();
- Serial.print("Gyroscope (dps): ");
- Serial.print(imu.g.x); Serial.print(", ");
- Serial.print(imu.g.y); Serial.print(", ");
- Serial.print(imu.g.z); Serial.println();
- Serial.print("Accelerometer (g): ");
- Serial.print(imu.a.x); Serial.print(", ");
- Serial.print(imu.a.y); Serial.print(", ");
- Serial.print(imu.a.z); Serial.println();
- Serial.print("Magnetometer (Gauss): ");
- Serial.print(compass.m.x); Serial.print(", ");
- Serial.print(compass.m.y); Serial.print(", ");
- Serial.print(compass.m.z); Serial.println();
- Serial.println();
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement