I'm trying to use the examples scrips in the NXPMotionSense library but I can't get it to work because it expects an MPL3115 altitude and temperature sensor despite it seemingly not being used for the orientation calculations.
I'm using an NXP Precision 9DoF FXOS8700+FXAS21002 breakout board, the library just expects the MPL3115 to also be there.
How do I get around this, is there a version of the library that excludes this sensor?
Cheers.
while (!FXOS8700_begin()) {
Serial.println("config error FXOS8700");
delay(1000);
}
while (!FXAS21002_begin()) {
Serial.println("config error FXAS21002");
delay(1000);
}
while (!MPL3115_begin()) {
Serial.println("config error MPL3115");
delay(1000);
}
I can't believe I got confused by this for 2 hours, and then 22 minutes after posting I figure out a work around, I'm gonna post the changes here in case anyone has the same issue.
I modified the two functions below from the NXPMotionSense.cpp file. I suppose I could have removed the sections that call them, but I don't know what kind of mischief that might cause.
bool NXPMotionSense::MPL3115_begin() // pressure
{
const uint8_t i2c_addr=MPL3115_I2C_ADDR;
uint8_t b;
return true; // <-------------------------------------------------------- This pretends I have the sensor
if (!read_regs(i2c_addr, MPL3115_WHO_AM_I, &b, 1)) return false;
//Serial.printf("MPL3115 ID = %02X\n", b);
if (b != 0xC4) return false;
// place into standby mode
if (!write_reg(i2c_addr, MPL3115_CTRL_REG1, 0)) return false;
// switch to active, altimeter mode, 512 ms measurement, polling mode
if (!write_reg(i2c_addr, MPL3115_CTRL_REG1, 0xB9)) return false;
// enable events
if (!write_reg(i2c_addr, MPL3115_PT_DATA_CFG, 0x07)) return false;
//Serial.println("MPL3115 Configured");
return true;
}
bool NXPMotionSense::MPL3115_read(int32_t *altitude, int16_t *temperature)
{
static elapsedMicros usec_since;
static int32_t usec_history=980000;
const uint8_t i2c_addr=MPL3115_I2C_ADDR;
uint8_t buf[6];
return false; // <-------------------------------------------------------- This ignores the read request
int32_t usec = usec_since;
if (usec + 500 < usec_history) return false;
if (!read_regs(i2c_addr, FXAS21002_STATUS, buf, 1)) return false;
if (buf[0] == 0) return false;
if (!read_regs(i2c_addr, buf, 6)) return false;
usec_since -= usec;
int diff = (usec - usec_history) >> 3;
if (diff < -1000) diff = -1000;
else if (diff > 1000) diff = 1000;
usec_history += diff;
int32_t a = ((uint32_t)buf[1] << 12) | ((uint16_t)buf[2] << 4) | (buf[3] >> 4);
if (a & 0x00080000) a |= 0xFFF00000;
*altitude = a;
*temperature = (int16_t)((buf[4] << 8) | buf[5]);
//Serial.printf("%02X %d %d: ", buf[0], usec, usec_history);
//Serial.printf("%6d,%6d", a, *temperature);
//Serial.println();
return true;
}