Skip to content

Commit

Permalink
Merge pull request #42 from ASU-ASCEND/LSM9DS1-Calibration
Browse files Browse the repository at this point in the history
Added LSM9DS1 sensor calibration code.
  • Loading branch information
SnailDragon authored Oct 17, 2024
2 parents e779fe2 + 49d5287 commit 0711613
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
47 changes: 47 additions & 0 deletions Testing/LSM9DS1-Calibration/LSM9DS1-Calibration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//LSM9DS1 Calibration Code

#include <SparkFunLSM9DS1.h>

LSM9DS1 IMU(SPI_MODE, 10); // Adjust CS pin accordingly

void setup() {
Serial.begin(115200);
if (!IMU.begin()) {
Serial.println("Failed to communicate with LSM9DS1.");
while (1);
}

// Calibrate sensors
calibrateGyro();
calibrateAccel();
}

void loop() {
// Read and output calibrated data
}

void calibrateGyro() {
// Implement gyroscope calibration as shown earlier
// Example
float gx, gy, gz;
int samples = 1000;
float gx_offset = 0, gy_offset = 0, gz_offset = 0;

for (int i = 0; i < samples; i++) {
IMU.readGyroscope(gx, gy, gz);
gx_offset += gx;
gy_offset += gy;
gz_offset += gz;
delay(2);
}

gx_offset /= samples;
gy_offset /= samples;
gz_offset /= samples;

// Store offsets for later use
}

void calibrateAccel() {
// Implement accelerometer calibration
}
9 changes: 7 additions & 2 deletions Testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ Protocol: **I<sup>2</sup>C**
Calibration: No calibration required as the INA260 is factory-calibrated.

#### [LSM9DS1](https://www.st.com/en/mems-and-sensors/lsm9ds1.html): 9-axis IMU
Protocol:
<br/>Calibration:
Protocol: I2C: Easy to use but slower data rates.
SPI: Preferred for faster sampling rates; recommended for high-speed applications.

<br/>Calibration: Necessary for accurate measurements. Perform offset calibration for accelerometer and gyroscope. Magnetometer calibration requires hard iron offset correction.

Libraries: SparkFun LSM9DS1 Library: Supports both I²C and SPI.
GitHub Repository: SparkFun_LSM9DS1_Arduino_Library

#### [MTK3339](https://www.adafruit.com/product/746): GPS
Protocol:
Expand Down

0 comments on commit 0711613

Please sign in to comment.