@@ -21,16 +21,43 @@ limitations under the License.
2121
2222#if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
2323
24- #include < Adafruit_LIS3MDL.h>
2524#include < Adafruit_LSM6DS33.h>
25+ #include < Adafruit_LIS3MDL.h>
2626
2727Adafruit_LSM6DS33 IMU; // Gyro and Accel
2828Adafruit_LIS3MDL IMUMag; // Magnetometer
2929
30- #else
30+ #if defined ARDUINO_NRF52840_FEATHER_SENSE
31+ // normalize sensor orientation to match Arduino nano
32+ void normalize_orientation (float & x, float & y, float & z)
33+ {
34+ (void ) x;
35+ (void ) z;
36+
37+ y = -y;
38+ }
39+
40+ #elif defined ARDUINO_NRF52840_CLUE
41+ // normalize sensor orientation to match Arduino nano
42+ void normalize_orientation (float & x, float & y, float & z)
43+ {
44+ float temp = x;
45+
46+ x = -y;
47+ y = temp; // x
48+ z = -z;
49+ }
50+ #endif
51+
52+ #else // For custom boards, please include your own sensor
3153
3254#error "Sensor driver library for your is not included"
33- // #include <Arduino_LSM9DS1.h> // change to Arduino_LSM6DS3.h for Nano 33 IoT or Uno WiFi Rev 2
55+
56+ // normalize sensor orientation to match Arduino nano
57+ void normalize_orientation (float & x, float & y, float & z)
58+ {
59+ (void ) x; (void ) y; (void ) z;
60+ }
3461
3562#endif
3663
@@ -106,6 +133,10 @@ namespace data_provider
106133 IMU.readAcceleration (ax, ay, az);
107134 IMU.readGyroscope (gx, gy, gz);
108135
136+ // normalize sensor orientation to match Arduino nano
137+ normalize_orientation (ax, ay, az);
138+ normalize_orientation (gx, gy, gz);
139+
109140 // Accelorameter has a range of -4 – 4
110141 buffer[0 ] = ax / 4.0 ;
111142 buffer[1 ] = ay / 4.0 ;
@@ -125,6 +156,10 @@ namespace data_provider
125156 if (IMUMag.magneticFieldAvailable ())
126157 {
127158 IMUMag.readMagneticField (mx, my, mz);
159+
160+ // normalize sensor orientation to match Arduino nano
161+ normalize_orientation (mx, my, mz);
162+
128163 lastMagneticFieldReading[0 ] = mx;
129164 lastMagneticFieldReading[1 ] = my;
130165 lastMagneticFieldReading[2 ] = mz;
0 commit comments