Are library's compatible across different ESP32 chips using Arduino IDE? MS5837 pressure sensor issue (SOLVED)

This is possibly a question better asked in an ESP32-specific forum so I might do that as well.

The same code on two different ESP32 projects gives different results. The sensor in question is the MS583702BA01 surface mount pressure sensor using I2C on both boards. Both boards use roughly the same layout with the appropriate I2C pull-up resisters.

The first board is an off-the-self ESP32-WROOM dev board and the second is an ESP32-C3-mini-1u-n4 module on a custom PCB.

This is the code I'm using on both and I'm using the Arduino IDE to compile and upload. I'm using the ESP32-WROOM or ESP32-C3-DEV under the board selection when compiling. The sensor library is from GitHub MS5837.

#include <Arduino.h>
#include <MS5837.h>
#include <Wire.h>

MS5837 sensor;

void setup(void)
{
  Serial.begin(9600);
  Wire.begin();
  sensor.init();
  sensor.setModel(MS5837::MS5837_02BA);

}

void loop(void) 
{
    sensor.read();
    Serial.println(sensor.pressure());
    Serial.println("------");
    delay(200); 
}

The sensor on the EPS32-WROOM dev board works fine and reads about 1000mbar. Using the same code, the ESP32-C3 number is around -100mbar which is all wrong. Also when I add some pressure to the line, ESP32-C3 goes positive to a point and then reverts back to negative with increased pressure while the ESP32-WROOM works as expected. I thought it might be a bad sensor but I've transplanted twice both a new sensor and from a working ESP32-WROOM project board to the ESP32-C3 board with the same results.

These ESPs have different CPU architectures so I'm guessing this might be the issue but I have zero knowledge on how to fix this. I posted on the repository but if someone knows what I can do to solve this when compiling for the different ESPs I'd be much appreciative.

Thanks in advanced!

Also, you might notice the IDE shows "WiFiduino32S3" on the C3 project. The ESP32-C3 module seems to show up as a different board every time I connect. (This module has a built-in UART to USB that I'm using.) Each time I program, I select the appropriate COM port and change the board selection to ESP32-C3 Dev. If I don't, the IO mapping is all wrong and I know I need to re-upload with the correct board selection.

Please read the topic "How to get the best out of this forum." It tells how to post information, code etc. The method is not by using screenshots...
Libraries are written for their selected controllers. The IDE doesn't change anything. Check the library documentation to find out what controllers it's made for.

Sorry, I did past the code above. The screenshots are simply to show the serial telemetry of the sensor results.

Best to post the telemetry as text, not an image, so it can be read.

Okay... I found "fixed" the issue but I'm not happy about it! This problem is most likely on my end and not in the library!

After an extensive troubleshooting session, I decided to just dump the raw register values from both sides. The short answer is that they are very different until I change the I2C speed on the ESP32-C3 side. The values fall in line somewhere between 70-80kbits. For some reason, the sensor was partially functional above 80kbits. It had a valid I2C address so I assumed everything was good to go! It would even report a pressure increase, but the value rollover was so strange.

Just thought I'd post in case someone wanted to know.

These are the same sensor on the same board just with a change in the I2C speed! :expressionless:

----80 kbits---
02:08:48.957 -> 0
02:08:49.035 -> 4207561 <--Raw pressure data should be around 6465444 typical from the datasheet!
02:08:50.020 -> 0181C178100138000000000000000000 <--Calibration register.
02:08:50.020 -> 0
02:08:50.098 -> 4207393
02:08:51.094 -> 0181C178100138000000000000000000
02:08:51.094 -> 0
02:08:51.141 -> 4207603
02:08:52.167 -> 0181C178100138000000000000000000
02:08:52.167 -> 0
02:08:52.207 -> 4207423
02:08:53.226 -> 0181C178100138000000000000000000

---70 kbits---
02:09:59.529 -> 0
02:09:59.576 -> 6569216 <--Correct value!
02:10:00.604 -> 01D1E97C5A813C000000000000000000 <--Calibration register.
02:10:00.604 -> 0
02:10:00.651 -> 6569337
02:10:01.659 -> 01D1E97C5A813C000000000000000000
02:10:01.659 -> 0
02:10:01.705 -> 6569187
02:10:02.726 -> 01D1E97C5A813C000000000000000000
02:10:02.726 -> 0
02:10:02.760 -> 6569158
02:10:03.759 -> 01D1E97C5A813C000000000000000000

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.