Skip to content

Add helper method to set IAQ humidity #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions adafruit_sgp30.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
"""
import time
from math import exp
from adafruit_bus_device.i2c_device import I2CDevice
from micropython import const

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

def set_iaq_relative_humidity(self, celcius, relative_humidity):
"""
Set the humidity in g/m3 for eCo2 and TVOC compensation algorithm.
The absolute humidity is calculated from the temperature and relative
humidity (as a percentage).
"""
numerator = ((relative_humidity / 100) * 6.112) * exp(
(17.62 * celcius) / (243.12 + celcius)
)
denominator = 273.15 + celcius

humidity_grams_pm3 = 216.7 * (numerator / denominator)
self.set_iaq_humidity(humidity_grams_pm3)

# Low level command functions

def _run_profile(self, profile):
Expand Down
1 change: 1 addition & 0 deletions examples/sgp30_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

sgp30.iaq_init()
sgp30.set_iaq_baseline(0x8973, 0x8AAE)
sgp30.set_iaq_relative_humidity(celcius=22.1, relative_humidity=44)

elapsed_sec = 0

Expand Down