Advertisement
microrobotics

Pololu AltIMU-10 v5 Gyro + Accelerometer + Compass + Altimeter:

Apr 3rd, 2023
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. This code reads the sensor data from the Pololu AltIMU-10 v5 Gyro + Accelerometer + Compass + Altimeter and prints the result on the Serial Monitor of the Arduino IDE. The LSM6 library is used to read the gyro and accelerometer data, the LIS3MDL library is used to read the magnetometer data, and the LPS22HB library is used to read the barometer data.
  3.  
  4. To use this code, connect the Pololu AltIMU-10 v5 Gyro + Accelerometer + Compass + Altimeter to the I2C pins of your Arduino board (usually A4 and A5 for most Arduino boards). The AltIMU-10 v5 should be powered with a 3.3-5V DC power source.
  5.  
  6. Note that the accuracy of the sensor readings can be affected by various factors, such as the orientation of the sensor, the temperature and humidity of the environment, and the calibration of the sensor.
  7. */
  8.  
  9. #include <Wire.h>
  10. #include <LSM6.h>
  11. #include <LIS3MDL.h>
  12. #include <LPS22HB.h>
  13.  
  14. LSM6 imu;
  15. LIS3MDL mag;
  16. LPS22HB baro;
  17.  
  18. void setup() {
  19.   Serial.begin(115200);
  20.  
  21.   Wire.begin();
  22.  
  23.   imu.init();
  24.   imu.enableDefault();
  25.   mag.init();
  26.   mag.enableDefault();
  27.   baro.init();
  28.   baro.enableDefault();
  29.  
  30.   Serial.println("AltIMU-10 v5 initialized");
  31. }
  32.  
  33. void loop() {
  34.   imu.read();
  35.   mag.read();
  36.   baro.read();
  37.  
  38.   float ax = imu.a.x;
  39.   float ay = imu.a.y;
  40.   float az = imu.a.z;
  41.   float gx = imu.g.x;
  42.   float gy = imu.g.y;
  43.   float gz = imu.g.z;
  44.   float mx = mag.m.x;
  45.   float my = mag.m.y;
  46.   float mz = mag.m.z;
  47.   float pressure = baro.readPressureMillibars();
  48.   float altitude = baro.readAltitudeMeters();
  49.  
  50.   Serial.print("Accelerometer: ");
  51.   Serial.print(ax);
  52.   Serial.print(", ");
  53.   Serial.print(ay);
  54.   Serial.print(", ");
  55.   Serial.print(az);
  56.   Serial.print("  Gyroscope: ");
  57.   Serial.print(gx);
  58.   Serial.print(", ");
  59.   Serial.print(gy);
  60.   Serial.print(", ");
  61.   Serial.print(gz);
  62.   Serial.print("  Magnetometer: ");
  63.   Serial.print(mx);
  64.   Serial.print(", ");
  65.   Serial.print(my);
  66.   Serial.print(", ");
  67.   Serial.print(mz);
  68.   Serial.print("  Pressure: ");
  69.   Serial.print(pressure);
  70.   Serial.print(" mbar  Altitude: ");
  71.   Serial.print(altitude);
  72.   Serial.println(" m");
  73.  
  74.   delay(1000);
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement