BAR02 for ESP32

I am using ESP32 for an IoT device that collected data underwater. I am also using Bar02 Ultra High Resolution 10m Depth/Pressure Sensor for a measuring the depth and temperature.

For other I2C pressure sensors like BMP280, if the device is not found, an error is given. But for BAR02 no error is given but only one data is shown

Altitude: 44307.70 m above mean sea level
Pressure: 0.00 mbar
Temperature: 20.00 deg C
Depth: -10.36 m

I guess the i2c bus hangs. I can use 3.3v or 5V. I tried both but it did not work. The code I used is from Blue Robotics example code

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

MS5837 sensor;

void setup() {

  sensor.setFluidDensity(997); // kg/m^3 (997 freshwater, 1029 for seawater)

void loop() {;

  Serial.print("Pressure: "); 
  Serial.println(" mbar");
  Serial.print("Temperature: "); 
  Serial.println(" deg C");
  Serial.print("Depth: "); 
  Serial.println(" m");
  Serial.print("Altitude: "); 
  Serial.println(" m above mean sea level");


Hi, please do not use 5V on SDA/SCL with the Bar02 sensor; it will damage the sensor.
Can you try adding external pullup resistors to pull the SCL/SDA lines to 3.3V? The Bar02 does not have on-board pullups, lots of other i2c modules like the bmp280 will have these on-board. The Arduino has internal pullups. The esp32 might have them, but you should make sure they are enabled (and still also try external pullups).

But, ESP32 gives 3.3V, it doesn’t have 5V pin.
So, there is no way I can use 5V for BAR02

I’m just making sure

Yeah, I thought I can. But, there is no 5V in ESP32.

I think we might have an ESP32 that we can test with @patrickelectric.