I have been using the SparkFun_MMA8452Q library with a number of ESP32 devices. I have found that it works reliably in a number of different configurations, connected to a variety of different pins, on an ESP32 Pico-D4 and an ESP32 WROVER kit. However I can’t get it to work on an ESP32S2 dev module. I have tried multiple combinations of pins, same code as used for the other two modules, but no joy. I get quite absurd values for the readings, like -185657920.0 g. The values are not consistent: I get various different large negative values, large positive values, zero and very occasionally values that at first glance appear plausible but bear no relationship to the orientation of the sensor.
I have added a debug print in one of the library functions as follows:
short MMA8452Q::getX()
{
byte rawData[2];
readRegisters(OUT_X_MSB, rawData, 2); // Read the X data into a data array
Serial.print(rawData[0], HEX); // debug print
Serial.print(rawData[1], HEX); // debug print
return ((short)(rawData[0] << 8 | rawData[1])) >> 4;
}
I am seeing with FF or F0 being printed every time, regardless of orientation of the sensor.
I am using the library thus:
bool MyIoTIn_MMA8452Q::_updateValues() {
bool rval = false;
int attempts = 2;
while(attempts--) {
if (sensor->available()) {
_lastX = sensor->getCalculatedX();
_lastY = sensor->getCalculatedY();
_lastZ = sensor->getCalculatedZ();
ESP_LOGV(TAG, "read %s name %s on pin %d", stype, &nameStr[0], pinIdx);
rval = true;
break;
}
if (!rval) Squirt::Error(String("MMA8452Q check: Failed to read MMA8452Q on pin ") + pinIdx);
}
return rval;
}
where sensor is defined as ```
MMA8452Q *sensor;
I am not seeing the ```
Squirt::Error
``` being hit, unless I disconnect a pin of the sensor.
I am having no trouble with any of my other sensors. I note that the MMA8452Q is the only I2C sensor I have.