SparkFun_MMA8452Q not working on ESP32S2

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.

I’ve seen a few folks that had similar issues and it was being caused by either esptool.py needing to be updated to the latest version, or needing to point the IDE to the latest branch of the esp32s2 IDF , both are here https://github.com/espressif/arduino-es … ster/tools - and here’s a somewhat similar post that might help viewtopic.php?f=182&t=56268&p=228087&hi … s2#p228087

Thanks for your reply. However the post you pointed to appears to show people having trouble getting the ESP32S2 working at all. That is not the problem I am experiencing. I have no trouble getting other things working on the ESP32S2. I have multiple different types of temperature sensor, temperature and humidity sensor, digital inputs analog inputs and interrupt driven inputs all working with the same code on ESP32S2, just the same as they do on the ESP32 and ESP32 Pico-D4. There are a few minor points where I have had to put preprocessor conditionals in to change the code for the ESP32S2, such as different timer interrupt handlers, however all three devices work from a common source.

My problem is this: Reading the MMA8452Q gives erroneous readings on the ESP32S2. The same code works on the ESP32 and the ESP32 Pico-D4.

Hmmm…sound like it’s a problem with the s2 firmware - it might be best to create an issue on the github here https://github.com/sparkfun/ESP32-S2_Thing_Plus/issues and see if the engineer can work something out :wink:

I was using the 2.0.0-alpha1 version of the board support . I have now upgraded to the 2.0.0 version - a bit of a journey as the board manager was giving me some sort of Null pointer exception so I had to delete the whole IDE and data package and reinstall from the ground up. I had to change references to LITTLEFS to use LittleFS instead - no big deal.

Unfortunately this has not made any change in this issue. I shall chase up elsewhere as I think this is an I2C driver issue.