Skip to content

Commit 74b64da

Browse files
committed
complete motion trainer with magnetic sensor
1 parent ec4713f commit 74b64da

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/.cluenrf52840.test.only

Whitespace-only changes.

libraries/Bluefruit52Lib/examples/Peripheral/tf4micro-motion-kit/.feather52840sense.test.only

Whitespace-only changes.

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ limitations under the License.
1818
* @author Rikard Lindstrom <rlindsrom@google.com>
1919
*/
2020
#include "data_provider.h"
21+
22+
#if defined(ARDUINO_NRF52840_CLUE) || defined(ARDUINO_NRF52840_FEATHER_SENSE)
23+
24+
#include <Adafruit_LIS3MDL.h>
25+
#include <Adafruit_LSM6DS33.h>
26+
27+
Adafruit_LSM6DS33 IMU; // Gyro and Accel
28+
Adafruit_LIS3MDL IMUMag; // Magnetometer
29+
30+
#else
31+
32+
#error "Sensor driver library for your is not included"
2133
//#include <Arduino_LSM9DS1.h> // change to Arduino_LSM6DS3.h for Nano 33 IoT or Uno WiFi Rev 2
22-
//#include <Arduino_LSM6DS3.h>
2334

24-
#include <Arduino_LSM6DSOX.h>
35+
#endif
2536

2637
namespace data_provider
2738
{
@@ -57,7 +68,7 @@ namespace data_provider
5768
bool setup()
5869
{
5970

60-
if (!IMU.begin())
71+
if ( !(IMU.begin_I2C() && IMUMag.begin_I2C()) )
6172
{
6273
Serial.println("Failed to initialized IMU!");
6374
return false;
@@ -74,10 +85,10 @@ namespace data_provider
7485
Serial.println(IMU.accelerationSampleRate());
7586
Serial.print("Gyroscope sample rate = ");
7687
Serial.println(IMU.gyroscopeSampleRate());
77-
#if 0
88+
7889
Serial.print("Magnetometer sample rate = ");
79-
Serial.println(IMU.magneticFieldSampleRate());
80-
#endif
90+
Serial.println(IMUMag.magneticFieldSampleRate());
91+
8192
return true;
8293
}
8394

@@ -105,16 +116,15 @@ namespace data_provider
105116
buffer[4] = gy / 2000.0;
106117
buffer[5] = gz / 2000.0;
107118

108-
#if 0
109119
if (useMagnetometer || calibrating)
110120
{
111121
float mx, my, mz;
112122

113123
// The Magnetometer sample rate is only 20hz, so we'll use previous values
114124
// if no new ones are available
115-
if (IMU.magneticFieldAvailable())
125+
if (IMUMag.magneticFieldAvailable())
116126
{
117-
IMU.readMagneticField(mx, my, mz);
127+
IMUMag.readMagneticField(mx, my, mz);
118128
lastMagneticFieldReading[0] = mx;
119129
lastMagneticFieldReading[1] = my;
120130
lastMagneticFieldReading[2] = mz;
@@ -161,6 +171,5 @@ namespace data_provider
161171
buffer[7] = my / 50.0;
162172
buffer[8] = mz / 50.0;
163173
}
164-
#endif
165174
}
166175
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void showErrorLed()
139139
{
140140
// blink red
141141
millis() % 1000 > 500 ? rgbLedOff() : rgbLedRed();
142-
delay(500);
142+
yield();
143143
}
144144

145145
void updateLed()
@@ -412,12 +412,10 @@ void setup()
412412
while (!Serial && millis() - startTime < 2000)
413413
yield();
414414

415-
Serial.println("Bluefruit52 Example");
416-
Serial.println("-------------------\n");
417-
418415
// Prepare LED pins.
419416
pinMode(LED_BUILTIN, OUTPUT);
420417
neopixels.begin();
418+
neopixels.setBrightness(0x20);
421419

422420
// Start IMU / Data provider.
423421
if (!data_provider::setup())

0 commit comments

Comments
 (0)