Skip to content

Commit 12a7d6e

Browse files
committed
Added dew point, updated example
1 parent afcde67 commit 12a7d6e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

adafruit_bme280.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ 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+
"""The dew point in Celsius using the Magnus forumula. Constants from Sontag, 1990."""
110+
b = 17.62
111+
c = 243.12
112+
gamma = (b * self.temperature /(c + self.temperature)) + math.log(self.humidity / 100.0)
113+
dewpoint = (c * gamma) / (b - gamma)
114+
return dewpoint
115+
116+
107117
@property
108118
def temperature(self):
109119
"""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)