Skip to content

Commit 4218f0d

Browse files
committed
Add helper method to set IAQ humidity
Most sensors only report relative humidity and temperature, so this uses the formula in the datasheet [^1] to make calibration easier. Notes: - The datasheet doesn't give the origin of the formula, but it seems to be based on Tetens Equation (to approximate pressure). - The example in the datasheet is wrong: the output should be 11.48. - math.exp is available in MicroPython [^2]. [^1]: https://sensirion.com/media/documents/984E0DD5/61644B8B/Sensirion_Gas_Sensors_Datasheet_SGP30.pdf [^2]: https://docs.micropython.org/en/latest/library/math.html#math.exp
1 parent 2fef7ee commit 4218f0d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

adafruit_sgp30.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
2626
"""
2727
import time
28+
from math import exp
2829
from adafruit_bus_device.i2c_device import I2CDevice
2930
from micropython import const
3031

@@ -168,6 +169,20 @@ def set_iaq_humidity(self, gramsPM3): # pylint: disable=invalid-name
168169
buffer += arr
169170
self._run_profile(["iaq_set_humidity", [0x20, 0x61] + buffer, 0, 0.01])
170171

172+
def set_iaq_relative_humidity(self, celcius, relative_humidity):
173+
"""
174+
Set the humidity in g/m3 for eCo2 and TVOC compensation algorithm.
175+
The absolute humidity is calculated from the temperature and relative
176+
humidity (as a percentage).
177+
"""
178+
numerator = ((relative_humidity / 100) * 6.112) * exp(
179+
(17.62 * celcius) / (243.12 + celcius)
180+
)
181+
denominator = 273.15 + celcius
182+
183+
humidity_grams_pm3 = 216.7 * (numerator / denominator)
184+
self.set_iaq_humidity(humidity_grams_pm3)
185+
171186
# Low level command functions
172187

173188
def _run_profile(self, profile):

0 commit comments

Comments
 (0)