Skip to content

Commit 0e1357d

Browse files
committed
normalize sensor orientation for feather sense and clue
1 parent b5820b0 commit 0e1357d

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/data_provider.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2727
Adafruit_LSM6DS33 IMU; // Gyro and Accel
2828
Adafruit_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;

libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/tf4micro-motion-kit.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ limitations under the License.
2525
// to include driver libraries for yours.
2626

2727
// For how to run this example check out following
28-
// https://experiments.withgoogle.com/tiny-motion-trainer
28+
// - https://github.com/googlecreativelab/tf4micro-motion-kit
29+
// - https://experiments.withgoogle.com/collection/tfliteformicrocontrollers
2930

3031
#define VERSION 5
3132
#define FLOAT_BYTE_SIZE 4

0 commit comments

Comments
 (0)