Skip to content

Commit f736263

Browse files
authored
Merge pull request #27 from jposada202020/updating_docs
updating SI Units
2 parents df0c9fc + a416817 commit f736263

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

adafruit_mpl3115a2.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def _poll_reg1(self, mask):
197197

198198
@property
199199
def pressure(self):
200-
"""Read the barometric pressure detected by the sensor in Pascals."""
200+
"""Read the barometric pressure detected by the sensor in Hectopascals."""
201201
# First poll for a measurement to be finished.
202202
self._poll_reg1(_MPL3115A2_CTRL_REG1_OST)
203203
# Set control bits for pressure reading.
@@ -254,7 +254,7 @@ def altitude(self):
254254

255255
@property
256256
def temperature(self):
257-
"""Read the temperature as measured by the sensor in degrees Celsius."""
257+
"""Read the temperature as measured by the sensor in Celsius."""
258258
# First poll for a measurement to be finished.
259259
self._poll_reg1(_MPL3115A2_CTRL_REG1_OST)
260260
# Initatiate a one-shot measurement
@@ -278,16 +278,16 @@ def temperature(self):
278278
def sealevel_pressure(self):
279279
"""Read and write the pressure at sea-level used to calculate altitude.
280280
You must look this up from a local weather or meteorological report for
281-
the best accuracy. This is a value in Pascals.
281+
the best accuracy. This is a value in Hectopascals.
282282
"""
283283
# Read the sea level pressure in bars.
284284
self._read_into(_MPL3115A2_BAR_IN_MSB, self._BUFFER, count=2)
285-
# Reconstruct 16-bit value and scale back to pascals.
285+
# Reconstruct 16-bit value and scale back to Hectopascals.
286286
pressure = (self._BUFFER[0] << 8) | self._BUFFER[1]
287-
return pressure * 2.0
287+
return pressure * 2.0 / 100
288288

289289
@sealevel_pressure.setter
290290
def sealevel_pressure(self, val):
291-
# Convert to bars of pressure and write to the sealevel register.
292-
bars = val // 2
291+
# Convert from hectopascals to bars of pressure and write to the sealevel register.
292+
bars = int(val * 50)
293293
self._write_u16_be(_MPL3115A2_BAR_IN_MSB, bars)

examples/mpl3115a2_simpletest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
# This value has to be looked up from your local weather forecast or meteorological
2222
# reports. It will change day by day and even hour by hour with weather
2323
# changes. Remember altitude estimation from barometric pressure is not exact!
24-
# Set this to a value in pascals:
25-
sensor.sealevel_pressure = 102250
24+
# Set this to a value in hectopascals:
25+
sensor.sealevel_pressure = 1022.5
2626

2727
# Main loop to read the sensor values and print them every second.
2828
while True:
2929
pressure = sensor.pressure
30-
print("Pressure: {0:0.3f} pascals".format(pressure))
30+
print("Pressure: {0:0.3f} hectopascals".format(pressure))
3131
altitude = sensor.altitude
3232
print("Altitude: {0:0.3f} meters".format(altitude))
3333
temperature = sensor.temperature
34-
print("Temperature: {0:0.3f} degrees Celsius".format(temperature))
34+
print("Temperature: {0:0.3f} Celsius".format(temperature))
3535
time.sleep(1.0)

0 commit comments

Comments
 (0)