I want to use acceleration and gyro values in loop to infer various things, and to do so, I’d like to read the IMU directly. Doesn’t look like any of the Tracker Edge motion interfaces support this, so I did a minified test to try and read the IMU - compiles clean with no errors, yet tailing the serial output all values read 0.00 no matter how I manipulate the unit in my hand.
I’m wondering what I’m missing, or if I can’t get there from here…?
/*
* Simple IMU test
*/
#include "Particle.h"
#include "tracker_config.h"
#include "tracker.h"
#include "bmi160.h"
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
SerialLogHandler logHandler(115200, LOG_LEVEL_TRACE);
Bmi160AccelerometerConfig config = {
.rate = 100.0, // Hz [0.78Hz -> 1600Hz]
.range = 2.0, // g [2g, 4g, 8g, 16g]
};
void setup()
{
delay(5000);
int ret = SYSTEM_ERROR_NONE;
ret = BMI160.begin(BMI160_SPI_INTERFACE, BMI160_SPI_CS_PIN, BMI160_INT_PIN);
if (ret != SYSTEM_ERROR_NONE) {
Log.error("BMI160.begin() failed");
}
Log.info("BMI160.begin() succeeded");
BMI160.reset();
BMI160.initAccelerometer(config);
BMI160.wakeup();
}
void loop()
{
Bmi160Accelerometer accel = {0};
BMI160.getAccelerometer(accel);
Log.info("x: %2.3f, y: %2.3f, z: %2.3f", accel.x, accel.y, accel.z);
delay(100);
}