From 1ceb82f1eb1b7befa225e656572b5f68edc2b740 Mon Sep 17 00:00:00 2001 From: santaimpersonator <36016723+santaimpersonator@users.noreply.github.com> Date: Thu, 31 Aug 2023 19:06:38 -0600 Subject: [PATCH 1/2] Fix Angle Calculations --- .../Example3_AngleCalculations.ino | 4 ++-- src/SparkFun_TMAG5273_Arduino_Library.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/Example3_AngleCalculations/Example3_AngleCalculations.ino b/examples/Example3_AngleCalculations/Example3_AngleCalculations.ino index 53effb7..7696d6e 100644 --- a/examples/Example3_AngleCalculations/Example3_AngleCalculations.ino +++ b/examples/Example3_AngleCalculations/Example3_AngleCalculations.ino @@ -53,8 +53,8 @@ void loop() float angleCalculation = sensor.getAngleResult(); Serial.print("XYX: "); - Serial.print(angleCalculation); - Serial.println(" mT"); + Serial.print(angleCalculation, 4); + Serial.println(" deg"); } else diff --git a/src/SparkFun_TMAG5273_Arduino_Library.cpp b/src/SparkFun_TMAG5273_Arduino_Library.cpp index 10b4229..677bc5f 100644 --- a/src/SparkFun_TMAG5273_Arduino_Library.cpp +++ b/src/SparkFun_TMAG5273_Arduino_Library.cpp @@ -2644,10 +2644,10 @@ float TMAG5273::getZData() /// @return Angle measurement result in degrees (float value) float TMAG5273::getAngleResult() { - int8_t angleLSB = 0; - int8_t angleMSB = 0; + uint8_t angleLSB = 0; + uint8_t angleMSB = 0; - angleLSB = readRegister(TMAG5273_REG_ANGLE_RESULT_LSB); + angleLSB = readRegister(TMAG5273_REG_ANGLE_RESULT_LSB) & 0b11111111; angleMSB = readRegister(TMAG5273_REG_ANGLE_RESULT_MSB); // Variable to hold the full angle MSB and LSB registers @@ -2663,7 +2663,7 @@ float TMAG5273::getAngleResult() angleReg = (angleMSB << 8) | angleLSB; // Removing the uneeded bits for the fraction value - decValue = (angleReg && (0b0000000000001111)) / 16; + decValue = float(angleLSB & 0b1111) / 16; // Shift off the decimal value (last 4 bits) angleVal = angleReg >> 4; From 22e1f92b9cb749702d020bbe3aaedf69459eaf8b Mon Sep 17 00:00:00 2001 From: MadisonC-SparkFun Date: Wed, 6 Sep 2023 12:41:17 -0600 Subject: [PATCH 2/2] Changed "deg" to degree symbol in example printing --- .../Example3_AngleCalculations/Example3_AngleCalculations.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Example3_AngleCalculations/Example3_AngleCalculations.ino b/examples/Example3_AngleCalculations/Example3_AngleCalculations.ino index 7696d6e..bdce1a5 100644 --- a/examples/Example3_AngleCalculations/Example3_AngleCalculations.ino +++ b/examples/Example3_AngleCalculations/Example3_AngleCalculations.ino @@ -54,7 +54,7 @@ void loop() Serial.print("XYX: "); Serial.print(angleCalculation, 4); - Serial.println(" deg"); + Serial.println("°"); } else