Skip to content
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

Added dew point, updated example #12

Merged
merged 2 commits into from
Aug 13, 2018
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
12 changes: 12 additions & 0 deletions adafruit_bme280.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ def _read_temperature(self):
self._t_fine = int(var1 + var2)
#print("t_fine: ", self.t_fine)

@property
def dew_point(self):
# pylint: disable=invalid-name
# Disable: c is a constant used in the Magnus formula
"""The dew point in Celsius using the Magnus formula. Constants from Sontag, 1990."""
b = 17.62
c = 243.12
gamma = (b * self.temperature /(c + self.temperature)) + math.log(self.humidity / 100.0)
dewpoint = (c * gamma) / (b - gamma)
return dewpoint
# pylint: enable=invalid-name

@property
def temperature(self):
"""The compensated temperature in degrees celsius."""
Expand Down
7 changes: 4 additions & 3 deletions examples/bme280_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

# OR create library object using our Bus SPI port
#spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
#bme_cs = digitalio.DigitalInOut(board.D10)
#bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# bme_cs = digitalio.DigitalInOut(board.D5)
# bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)

# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25
Expand All @@ -21,4 +21,5 @@
print("Humidity: %0.1f %%" % bme280.humidity)
print("Pressure: %0.1f hPa" % bme280.pressure)
print("Altitude = %0.2f meters" % bme280.altitude)
print("Dew point = %0.1f C" % bme280.dew_point)
time.sleep(2)