Skip to content

Commit 3e90660

Browse files
authored
Merge pull request #35 from benthorner/main
Add helper method to set IAQ humidity
2 parents 082f9c8 + 519c908 commit 3e90660

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-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):

examples/sgp30_simpletest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
sgp30.iaq_init()
1919
sgp30.set_iaq_baseline(0x8973, 0x8AAE)
20+
sgp30.set_iaq_relative_humidity(celcius=22.1, relative_humidity=44)
2021

2122
elapsed_sec = 0
2223

0 commit comments

Comments
 (0)