diff --git a/adafruit_bme280.py b/adafruit_bme280.py index 5078dba..9eadfae 100644 --- a/adafruit_bme280.py +++ b/adafruit_bme280.py @@ -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.""" diff --git a/examples/bme280_simpletest.py b/examples/bme280_simpletest.py index c85a3f1..664a296 100644 --- a/examples/bme280_simpletest.py +++ b/examples/bme280_simpletest.py @@ -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 @@ -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)