Skip to content

Commit ac1bc89

Browse files
authored
Merge pull request #12 from kattni/add-dew-point
Added dew point, updated example
2 parents afcde67 + cdd59a1 commit ac1bc89

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

adafruit_bme280.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ def _read_temperature(self):
104104
self._t_fine = int(var1 + var2)
105105
#print("t_fine: ", self.t_fine)
106106

107+
@property
108+
def dew_point(self):
109+
# pylint: disable=invalid-name
110+
# Disable: c is a constant used in the Magnus formula
111+
"""The dew point in Celsius using the Magnus formula. Constants from Sontag, 1990."""
112+
b = 17.62
113+
c = 243.12
114+
gamma = (b * self.temperature /(c + self.temperature)) + math.log(self.humidity / 100.0)
115+
dewpoint = (c * gamma) / (b - gamma)
116+
return dewpoint
117+
# pylint: enable=invalid-name
118+
107119
@property
108120
def temperature(self):
109121
"""The compensated temperature in degrees celsius."""

examples/bme280_simpletest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
1010

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

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

0 commit comments

Comments
 (0)