Skip to content

Added sensor properties + example to reflect consistency changes #6

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 3 commits into from
Jun 1, 2018
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
25 changes: 25 additions & 0 deletions adafruit_sgp30.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ def __init__(self, i2c, address=_SGP30_DEFAULT_I2C_ADDR):
raise RuntimeError('SGP30 Not detected')
self.iaq_init()


@property
def tvoc(self):
"""Total Volatile Organic Compound in parts per billion."""
return self.iaq_measure()[1]


@property
def baseline_tvoc(self):
"""Total Volatile Organic Compound baseline value"""
return self.get_iaq_baseline()[1]


@property
def co2eq(self):
"""Carbon Dioxide Equivalent in parts per million"""
return self.iaq_measure()[0]


@property
def baseline_co2eq(self):
"""Carbon Dioxide Equivalent baseline value"""
return self.get_iaq_baseline()[0]


def iaq_init(self):
"""Initialize the IAQ algorithm"""
# name, command, signals, delay
Expand Down
5 changes: 3 additions & 2 deletions examples/sgp30_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

while True:
co2eq, tvoc = sgp30.iaq_measure()
print("CO2eq = %d ppm \t TVOC = %d ppb" % (co2eq, tvoc))
print("co2eq = %d ppm \t tvoc = %d ppb" % (sgp30.co2eq, sgp30.tvoc))
time.sleep(1)
elapsed_sec += 1
if elapsed_sec > 10:
elapsed_sec = 0
co2eq_base, tvoc_base = sgp30.get_iaq_baseline()
print("**** Baseline values: CO2eq = 0x%x, TVOC = 0x%x" % (co2eq_base, tvoc_base))
print("**** Baseline values: co2eq = 0x%x, tvoc = 0x%x"
% (sgp30.baseline_co2eq, sgp30.baseline_tvoc))