diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/data_provider.cpp b/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/data_provider.cpp index 5a79573d..70a432e9 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/data_provider.cpp +++ b/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/data_provider.cpp @@ -21,16 +21,43 @@ limitations under the License. #if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE) -#include #include +#include Adafruit_LSM6DS33 IMU; // Gyro and Accel Adafruit_LIS3MDL IMUMag; // Magnetometer -#else +#if defined ARDUINO_NRF52840_FEATHER_SENSE + // normalize sensor orientation to match Arduino nano + void normalize_orientation(float& x, float& y, float& z) + { + (void) x; + (void) z; + + y = -y; + } + +#elif defined ARDUINO_NRF52840_CLUE + // normalize sensor orientation to match Arduino nano + void normalize_orientation(float& x, float& y, float& z) + { + float temp = x; + + x = -y; + y = temp; // x + z = -z; + } +#endif + +#else // For custom boards, please include your own sensor #error "Sensor driver library for your is not included" -//#include // change to Arduino_LSM6DS3.h for Nano 33 IoT or Uno WiFi Rev 2 + +// normalize sensor orientation to match Arduino nano +void normalize_orientation(float& x, float& y, float& z) +{ + (void) x; (void) y; (void) z; +} #endif @@ -106,6 +133,10 @@ namespace data_provider IMU.readAcceleration(ax, ay, az); IMU.readGyroscope(gx, gy, gz); + // normalize sensor orientation to match Arduino nano + normalize_orientation(ax, ay, az); + normalize_orientation(gx, gy, gz); + // Accelorameter has a range of -4 – 4 buffer[0] = ax / 4.0; buffer[1] = ay / 4.0; @@ -125,6 +156,10 @@ namespace data_provider if (IMUMag.magneticFieldAvailable()) { IMUMag.readMagneticField(mx, my, mz); + + // normalize sensor orientation to match Arduino nano + normalize_orientation(mx, my, mz); + lastMagneticFieldReading[0] = mx; lastMagneticFieldReading[1] = my; lastMagneticFieldReading[2] = mz; diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/tf4micro-motion-kit.ino b/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/tf4micro-motion-kit.ino index 55ddaf52..b18cac67 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/tf4micro-motion-kit.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/tf4micro-motion-kit.ino @@ -25,7 +25,8 @@ limitations under the License. // to include driver libraries for yours. // For how to run this example check out following -// https://experiments.withgoogle.com/tiny-motion-trainer +// - https://github.com/googlecreativelab/tf4micro-motion-kit +// - https://experiments.withgoogle.com/collection/tfliteformicrocontrollers #define VERSION 5 #define FLOAT_BYTE_SIZE 4