diff --git a/MIDAS/platformio.ini b/MIDAS/platformio.ini
index 2f52aeb4..c35ad6bc 100644
--- a/MIDAS/platformio.ini
+++ b/MIDAS/platformio.ini
@@ -13,7 +13,8 @@ build_flags =
build_unflags =
-std=gnu++11
lib_deps =
- adafruit/Adafruit LIS3MDL@^1.2.1 ; Magnetometer driver
+ adafruit/Adafruit LIS3MDL@^1.2.1 ; Old magnetometer driver, Adafruit_BNO08x fails or else
+ sparkfun/SparkFun MMC5983MA Magnetometer Arduino Library@^1.1.4 ; Magnetometer driver
sparkfun/SparkFun u-blox GNSS v3@^3.1.8 ; GPS
build_src_filter = +<*> - + -
@@ -33,7 +34,8 @@ build_flags =
build_unflags =
-std=gnu++11
lib_deps =
- adafruit/Adafruit LIS3MDL@^1.2.1 ; Magnetometer driver
+ adafruit/Adafruit LIS3MDL@^1.2.1 ; Old magnetometer driver, Adafruit_BNO08x fails or else
+ sparkfun/SparkFun MMC5983MA Magnetometer Arduino Library@^1.1.4 ; Magnetometer driver
sparkfun/SparkFun u-blox GNSS v3@^3.1.8 ; GPS
build_src_filter = +<*> - + -
diff --git a/MIDAS/src/hardware/Magnetometer.cpp b/MIDAS/src/hardware/Magnetometer.cpp
index 23ef322d..a44d0360 100644
--- a/MIDAS/src/hardware/Magnetometer.cpp
+++ b/MIDAS/src/hardware/Magnetometer.cpp
@@ -1,27 +1,29 @@
-#include
+#include
#include "sensors.h"
#include "hal.h"
-Adafruit_LIS3MDL LIS3MDL; // global static instance of the sensor
+SFE_MMC5983MA MMC5983; // global static instance of the sensor
ErrorCode MagnetometerSensor::init() {
- if (!LIS3MDL.begin_SPI(LIS3MDL_CS)) { // Checks if sensor is connected
+ if (MMC5983.begin(MMC5983_CS) == false) { // Checks if sensor is connected
return ErrorCode::MagnetometerCouldNotBeInitialized;
}
- LIS3MDL.setOperationMode(LIS3MDL_CONTINUOUSMODE); // Reading continuously, instead of single-shot or off
- LIS3MDL.setDataRate(LIS3MDL_DATARATE_155_HZ);
- LIS3MDL.setRange(LIS3MDL_RANGE_4_GAUSS); // Earth's magnetic field is 1/2 gauss, can detect high current
return ErrorCode::NoError;
}
Magnetometer MagnetometerSensor::read() {
// read from aforementioned global instance of sensor
- LIS3MDL.read();
+ uint32_t cx, cy, cz;
+ double X, Y, Z;
- float mx = LIS3MDL.x_gauss;
- float my = LIS3MDL.y_gauss;
- float mz = LIS3MDL.z_gauss;
- Magnetometer reading{mx, my, mz};
+ MMC5983.getMeasurementXYZ(&cx, &cy, &cz);
+
+ double sf = (double)(1 << 17);
+ X = ((double)cx - sf)/sf;
+ Y = ((double)cy - sf)/sf;
+ Z = ((double)cz - sf)/sf;
+
+ Magnetometer reading{X, Y, Z};
return reading;
}
diff --git a/MIDAS/src/hardware/main.cpp b/MIDAS/src/hardware/main.cpp
index 4985d40f..fc8e7a60 100644
--- a/MIDAS/src/hardware/main.cpp
+++ b/MIDAS/src/hardware/main.cpp
@@ -78,7 +78,7 @@ void setup()
pinMode(LSM6DS3_CS, OUTPUT);
pinMode(KX134_CS, OUTPUT);
pinMode(ADXL355_CS, OUTPUT);
- pinMode(LIS3MDL_CS, OUTPUT);
+ pinMode(MMC5983_CS, OUTPUT);
pinMode(BNO086_CS, OUTPUT);
pinMode(BNO086_RESET, OUTPUT);
pinMode(CAN_CS, OUTPUT);
@@ -89,7 +89,7 @@ void setup()
digitalWrite(LSM6DS3_CS, HIGH);
digitalWrite(KX134_CS, HIGH);
digitalWrite(ADXL355_CS, HIGH);
- digitalWrite(LIS3MDL_CS, HIGH);
+ digitalWrite(MMC5983_CS, HIGH);
digitalWrite(BNO086_CS, HIGH);
digitalWrite(CAN_CS, HIGH);
digitalWrite(E22_CS, HIGH);
diff --git a/MIDAS/src/hardware/pins.h b/MIDAS/src/hardware/pins.h
index 60724c40..ec7ab690 100644
--- a/MIDAS/src/hardware/pins.h
+++ b/MIDAS/src/hardware/pins.h
@@ -18,7 +18,8 @@
#define ADXL355_CS 44
// magnetometer chip select
-#define LIS3MDL_CS 35
+#define MMC5983_CS 4
+#define MMC5983_INT 7
// orientation chip select, interrupt
#define BNO086_CS 48
@@ -92,4 +93,4 @@
#define FLASH_DAT2 15
#define FLASH_DAT3 16
-#define GPIO_RESET 47
\ No newline at end of file
+#define GPIO_RESET 47
diff --git a/MIDAS/src/sensor_data.h b/MIDAS/src/sensor_data.h
index 47358997..92d8d1f4 100644
--- a/MIDAS/src/sensor_data.h
+++ b/MIDAS/src/sensor_data.h
@@ -166,9 +166,9 @@ struct GPS {
* @brief data from the magnetometer
*/
struct Magnetometer {
- float mx;
- float my;
- float mz;
+ double mx;
+ double my;
+ double mz;
};
struct Quaternion {
@@ -275,4 +275,4 @@ struct PyroState {
struct CameraData {
uint8_t camera_state = 255;
float camera_voltage = 0;
-};
\ No newline at end of file
+};