Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions adafruit_scd30.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ def __init__(self, i2c_bus, ambient_pressure=0, address=SCD30_DEFAULT_ADDR):

self.reset()

# set continuous measurement interval in seconds
self.measurement_interval = 2
# activate automatic self-calibration
self.self_calibration_enabled = True
# sets ambient pressure and starts continuous measurements
# trigger continuous measurements with optional ambient pressure compensation
self.ambient_pressure = ambient_pressure

# cached readings
Expand All @@ -76,7 +78,14 @@ def __init__(self, i2c_bus, ambient_pressure=0, address=SCD30_DEFAULT_ADDR):
def reset(self):
"""Perform a soft reset on the sensor, restoring default values"""
self._send_command(_CMD_SOFT_RESET)
sleep(0.030) # not mentioned by datasheet, but required to avoid IO error
sleep(0.1) # not mentioned by datasheet, but required to avoid IO error
# pylint:disable=protected-access
# are we using Blinka?
if hasattr(self.i2c_device.i2c, "_i2c"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id kinda sorta prefer not having this here but instead in a new simple example just for mcp2221 if thats ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd have to remove the call to reset() in __init__, which is maybe OK? otherwise you can't even instantiate with mcp2221.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.<
ridiculous sensor.
ok move the reset() out of init and into the example too

# with an MCP2221?
if hasattr(self.i2c_device.i2c._i2c, "_mcp2221"):
# then lets reset that too
self.i2c_device.i2c._i2c._mcp2221._reset()

@property
def measurement_interval(self):
Expand Down Expand Up @@ -108,6 +117,8 @@ def self_calibration_enabled(self):
@self_calibration_enabled.setter
def self_calibration_enabled(self, enabled):
self._send_command(_CMD_AUTOMATIC_SELF_CALIBRATION, enabled)
if enabled:
sleep(0.01)

@property
def data_available(self):
Expand Down Expand Up @@ -196,7 +207,7 @@ def temperature(self):
def relative_humidity(self):
"""Returns the current relative humidity in %rH.

**NOTE** Between measurements, the most recent reading will be cached and returned. """
**NOTE** Between measurements, the most recent reading will be cached and returned."""
if self.data_available:
self._read_data()
return self._relative_humidity
Expand Down