Skip to content

Commit

Permalink
Fixed pressure unit conversion error
Browse files Browse the repository at this point in the history
  • Loading branch information
titonbarua committed Jan 1, 2025
1 parent 7e98700 commit d6aa943
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ms5837/bar02.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _calc_pressure_temp(self, raw_p, raw_t):
TEMP2 = (TEMP - Ti) * 0.01 # degree-C
P2 = (
(((D1 * SENS2) >> 21) - OFF2) >> 15
) * 0.01 # mBar = KPa
) * 0.001 # 1 KPa = 10 mBar

# Units: (KPa, degree-C)
return P2, TEMP2
2 changes: 1 addition & 1 deletion ms5837/bar30.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _calc_pressure_temp(self, raw_p, raw_t):
TEMP2 = (TEMP - Ti) * 0.01 # °C
P2 = (
(((D1 * SENS2) >> 21) - OFF2) >> 13
) * 0.1 # mBar = KPa
) * 0.01 # 1 KPa = 10 mBar

# Units: (KPa, degree-C)
return P2, TEMP2
4 changes: 2 additions & 2 deletions ms5837/depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(
self._p_ref = float(ref_pressure)

def set_ref_pressure(self, n_measurements=10):
"""Set reference pressure from measurements by the sensor."""
"""Set reference pressure in KPa from measurements by the sensor."""
s = 0.0
for _ in range(n_measurements):
p_abs, _ = self._ms5837.read()
Expand All @@ -48,7 +48,7 @@ def _calc_depth_m(self, abs_pressure):

# Liquid pressure, P = h x rho x g
# => h = P / (rho x g)
h = (p_rel * 100.0) / self._g_x_rho
h = (p_rel * 1000.0) / self._g_x_rho

# Unit: m
return h
Expand Down
4 changes: 1 addition & 3 deletions tests/rp2040_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ def _create_sensor(type_, osr):
return (i2c_obj, sensor)


# _OSR_RATES = [256, 512, 1024, 2048, 4096]
_BAR30_OSR_RATES = [256, 512, 1024, 2048, 4096]
_BAR02_OSR_RATES = [256, 512, 1024, 2048, 4096, 8192]
# [256, 512, 1024, 2048, 4096]

# Number of measurements per OSR for timing.
_N = 100
Expand Down Expand Up @@ -257,7 +255,7 @@ def print_depth(sensor_type, water_density=1000, interval_sec=1.0):
while True:
try:
d_m = depth_estimator.read_depth()
print("Depth: {:.2f} mm".format(d_m * 1000))
print("Depth: {:+.3f} cm".format(d_m * 100))
time.sleep(interval_sec)
except KeyboardInterrupt:
break
Expand Down

0 comments on commit d6aa943

Please sign in to comment.