# BAR02 for ESP32

**URL:** <https://discuss.bluerobotics.com/t/bar02-for-esp32/3848>\
**Category:** General Discussion\
**Created:** [December 4, 2018, 3:26pm UTC](https://discuss.bluerobotics.com/t/bar02-for-esp32/3848 "2018-12-04T15:26:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adnansabbir](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@adnansabbir](https://discuss.bluerobotics.com/u/adnansabbir)\
**Post date:** [December 4, 2018, 3:26pm UTC](https://discuss.bluerobotics.com/t/bar02-for-esp32/3848/1 "2018-12-04T15:26:19Z")

</div>

Hi,  
I am using ESP32 for an IoT device that collected data underwater. I am also using [Bar02 Ultra High Resolution 10m Depth/Pressure Sensor](https://bluerobotics.com/store/electronics/bar02-sensor-r1-rp/) 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() {
  
  Serial.begin(9600);
  
  Serial.println("Starting");
  
  Wire.begin();

  sensor.setModel(MS5837::MS5837_02BA);
  sensor.init();
  
  sensor.setFluidDensity(997); // kg/m^3 (997 freshwater, 1029 for seawater)
}

void loop() {

  sensor.read();

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

  delay(1000);
}

```

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [December 4, 2018, 4:22pm UTC](https://discuss.bluerobotics.com/t/bar02-for-esp32/3848/2 "2018-12-04T16:22:47Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![adnansabbir](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@adnansabbir](https://discuss.bluerobotics.com/u/adnansabbir)\
**Post date:** [December 4, 2018, 5:56pm UTC](https://discuss.bluerobotics.com/t/bar02-for-esp32/3848/3 "2018-12-04T17:56:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [December 4, 2018, 8:04pm UTC](https://discuss.bluerobotics.com/t/bar02-for-esp32/3848/4 "2018-12-04T20:04:59Z")

</div>

I’m just making sure

> [@adnansabbir](#):
>
> I guess the i2c bus hangs. I can use 3.3v or 5V. I tried both but it did not work.

---

<div class="post-metadata">

**Author:** ![adnansabbir](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@adnansabbir](https://discuss.bluerobotics.com/u/adnansabbir)\
**Post date:** [December 4, 2018, 9:52pm UTC](https://discuss.bluerobotics.com/t/bar02-for-esp32/3848/5 "2018-12-04T21:52:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [December 5, 2018, 3:09pm UTC](https://discuss.bluerobotics.com/t/bar02-for-esp32/3848/7 "2018-12-05T15:09:37Z")

</div>

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