@@ -21,16 +21,43 @@ limitations under the License.
21
21
22
22
#if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
23
23
24
- #include < Adafruit_LIS3MDL.h>
25
24
#include < Adafruit_LSM6DS33.h>
25
+ #include < Adafruit_LIS3MDL.h>
26
26
27
27
Adafruit_LSM6DS33 IMU; // Gyro and Accel
28
28
Adafruit_LIS3MDL IMUMag; // Magnetometer
29
29
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
31
53
32
54
#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
+ }
34
61
35
62
#endif
36
63
@@ -106,6 +133,10 @@ namespace data_provider
106
133
IMU.readAcceleration (ax, ay, az);
107
134
IMU.readGyroscope (gx, gy, gz);
108
135
136
+ // normalize sensor orientation to match Arduino nano
137
+ normalize_orientation (ax, ay, az);
138
+ normalize_orientation (gx, gy, gz);
139
+
109
140
// Accelorameter has a range of -4 – 4
110
141
buffer[0 ] = ax / 4.0 ;
111
142
buffer[1 ] = ay / 4.0 ;
@@ -125,6 +156,10 @@ namespace data_provider
125
156
if (IMUMag.magneticFieldAvailable ())
126
157
{
127
158
IMUMag.readMagneticField (mx, my, mz);
159
+
160
+ // normalize sensor orientation to match Arduino nano
161
+ normalize_orientation (mx, my, mz);
162
+
128
163
lastMagneticFieldReading[0 ] = mx;
129
164
lastMagneticFieldReading[1 ] = my;
130
165
lastMagneticFieldReading[2 ] = mz;
0 commit comments