From ded08dd81f46bc6968c3f044105135591d742233 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 Jul 2020 13:36:30 -0400 Subject: [PATCH 1/4] Added temperature offset --- adafruit_bme680.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/adafruit_bme680.py b/adafruit_bme680.py index 4971e21..57a9e53 100644 --- a/adafruit_bme680.py +++ b/adafruit_bme680.py @@ -142,9 +142,11 @@ class Adafruit_BME680: :param int refresh_rate: Maximum number of readings per second. Faster property reads will be from the previous reading.""" - def __init__(self, *, refresh_rate=10): + def __init__(self, *, refresh_rate=10, temp_offset=5): """Check the BME680 was found, read the coefficients and enable the sensor for continuous reads.""" + + self._write(_BME680_REG_SOFTRESET, [0xB6]) time.sleep(0.005) @@ -178,6 +180,9 @@ def __init__(self, *, refresh_rate=10): self._last_reading = 0 self._min_refresh_time = 1 / refresh_rate + # Set up temperature offset + self.temp_offset = temp_offset + @property def pressure_oversample(self): """The oversampling for pressure sensor""" @@ -231,7 +236,7 @@ def temperature(self): """The compensated temperature in degrees celsius.""" self._perform_reading() calc_temp = ((self._t_fine * 5) + 128) / 256 - return calc_temp / 100 + return (calc_temp / 100) - self.temp_offset @property def pressure(self): From c5c1edaca90784e1af09f8764c092e67d43c99cd Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 Jul 2020 13:39:25 -0400 Subject: [PATCH 2/4] Formatting --- adafruit_bme680.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_bme680.py b/adafruit_bme680.py index 57a9e53..91594ea 100644 --- a/adafruit_bme680.py +++ b/adafruit_bme680.py @@ -146,7 +146,6 @@ def __init__(self, *, refresh_rate=10, temp_offset=5): """Check the BME680 was found, read the coefficients and enable the sensor for continuous reads.""" - self._write(_BME680_REG_SOFTRESET, [0xB6]) time.sleep(0.005) From 3adfd8a15118d1bfec21a9a5413922cc724b7802 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 27 Jul 2020 09:37:30 -0400 Subject: [PATCH 3/4] Moved offset to simpletest --- adafruit_bme680.py | 8 ++------ examples/bme680_simpletest.py | 4 +++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/adafruit_bme680.py b/adafruit_bme680.py index 91594ea..4971e21 100644 --- a/adafruit_bme680.py +++ b/adafruit_bme680.py @@ -142,10 +142,9 @@ class Adafruit_BME680: :param int refresh_rate: Maximum number of readings per second. Faster property reads will be from the previous reading.""" - def __init__(self, *, refresh_rate=10, temp_offset=5): + def __init__(self, *, refresh_rate=10): """Check the BME680 was found, read the coefficients and enable the sensor for continuous reads.""" - self._write(_BME680_REG_SOFTRESET, [0xB6]) time.sleep(0.005) @@ -179,9 +178,6 @@ def __init__(self, *, refresh_rate=10, temp_offset=5): self._last_reading = 0 self._min_refresh_time = 1 / refresh_rate - # Set up temperature offset - self.temp_offset = temp_offset - @property def pressure_oversample(self): """The oversampling for pressure sensor""" @@ -235,7 +231,7 @@ def temperature(self): """The compensated temperature in degrees celsius.""" self._perform_reading() calc_temp = ((self._t_fine * 5) + 128) / 256 - return (calc_temp / 100) - self.temp_offset + return calc_temp / 100 @property def pressure(self): diff --git a/examples/bme680_simpletest.py b/examples/bme680_simpletest.py index a1bb9cd..71aa8b5 100644 --- a/examples/bme680_simpletest.py +++ b/examples/bme680_simpletest.py @@ -11,7 +11,9 @@ bme680.sea_level_pressure = 1013.25 while True: - print("\nTemperature: %0.1f C" % bme680.temperature) + # You will usually have to add an offset to account for the temperature of + # the sensor. This is usually around 5 degrees. + print("\nTemperature: %0.1f C" % bme680.temperature - 5) print("Gas: %d ohm" % bme680.gas) print("Humidity: %0.1f %%" % bme680.humidity) print("Pressure: %0.3f hPa" % bme680.pressure) From 64d2709a312f07947f226dfaf06e2e62eb238157 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 28 Jul 2020 11:13:46 -0400 Subject: [PATCH 4/4] Made requested changes to clarify temperature offset --- examples/bme680_simpletest.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/bme680_simpletest.py b/examples/bme680_simpletest.py index 71aa8b5..31ed526 100644 --- a/examples/bme680_simpletest.py +++ b/examples/bme680_simpletest.py @@ -10,10 +10,13 @@ # change this to match the location's pressure (hPa) at sea level bme680.sea_level_pressure = 1013.25 +# You will usually have to add an offset to account for the temperature of +# the sensor. This is usually around 5 degrees but varies by use. Use a +# separate temperature sensor to calibrate this one. +temperature_offset = -5 + while True: - # You will usually have to add an offset to account for the temperature of - # the sensor. This is usually around 5 degrees. - print("\nTemperature: %0.1f C" % bme680.temperature - 5) + print("\nTemperature: %0.1f C" % bme680.temperature + temperature_offset) print("Gas: %d ohm" % bme680.gas) print("Humidity: %0.1f %%" % bme680.humidity) print("Pressure: %0.3f hPa" % bme680.pressure)