Skip to content

updating SI Units #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions adafruit_mpl3115a2.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _poll_reg1(self, mask):

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

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

@sealevel_pressure.setter
def sealevel_pressure(self, val):
# Convert to bars of pressure and write to the sealevel register.
bars = val // 2
# Convert from hectopascals to bars of pressure and write to the sealevel register.
bars = int(val * 50)
self._write_u16_be(_MPL3115A2_BAR_IN_MSB, bars)
8 changes: 4 additions & 4 deletions examples/mpl3115a2_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
# This value has to be looked up from your local weather forecast or meteorological
# reports. It will change day by day and even hour by hour with weather
# changes. Remember altitude estimation from barometric pressure is not exact!
# Set this to a value in pascals:
sensor.sealevel_pressure = 102250
# Set this to a value in hectopascals:
sensor.sealevel_pressure = 1022.5

# Main loop to read the sensor values and print them every second.
while True:
pressure = sensor.pressure
print("Pressure: {0:0.3f} pascals".format(pressure))
print("Pressure: {0:0.3f} hectopascals".format(pressure))
altitude = sensor.altitude
print("Altitude: {0:0.3f} meters".format(altitude))
temperature = sensor.temperature
print("Temperature: {0:0.3f} degrees Celsius".format(temperature))
print("Temperature: {0:0.3f} Celsius".format(temperature))
time.sleep(1.0)