diff --git a/README.rst b/README.rst index 823cbf1..90e30dc 100644 --- a/README.rst +++ b/README.rst @@ -64,10 +64,9 @@ Usage Example import time import board - import busio import adafruit_scd30 - i2c = busio.I2C(board.SCL, board.SDA) + i2c = board.I2C() # uses board.SCL and board.SDA scd = adafruit_scd30.SCD30(i2c) while True: diff --git a/adafruit_scd30.py b/adafruit_scd30.py index 39407d6..ff365e7 100644 --- a/adafruit_scd30.py +++ b/adafruit_scd30.py @@ -50,7 +50,40 @@ class SCD30: - """CircuitPython helper class for using the SCD30 CO2 sensor""" + """ + CircuitPython helper class for using the SCD30 CO2 sensor + + :param ~busio.I2C i2c_bus: The I2C bus the SCD30 is connected to. + :param int ambient_pressure: Ambient pressure compensation. Defaults to :const:`0` + :param int address: The I2C device address for the sensor. Default is :const:`0x61` + + **Quickstart: Importing and using the SCD30** + + Here is an example of using the :class:`SCD30` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + import adafruit_scd30 + + Once this is done you can define your `board.I2C` object and define your sensor object + + .. code-block:: python + + i2c = board.I2C() # uses board.SCL and board.SDA + scd = adafruit_scd30.SCD30(i2c) + + Now you have access to the CO2, temperature and humidity using + the :attr:`CO2`, :attr:`temperature` and :attr:`relative_humidity` attributes + + .. code-block:: python + + temperature = scd.temperature + relative_humidity = scd.relative_humidity + co2_ppm_level = scd.CO2 + + """ def __init__(self, i2c_bus, ambient_pressure=0, address=SCD30_DEFAULT_ADDR): if ambient_pressure != 0: @@ -80,7 +113,10 @@ def reset(self): def measurement_interval(self): """Sets the interval between readings in seconds. The interval value must be from 2-1800 - **NOTE** This value will be saved and will not be reset on boot or by calling `reset`.""" + .. note:: + This value will be saved and will not be reset on boot or by calling `reset`. + + """ return self._read_register(_CMD_SET_MEASUREMENT_INTERVAL) @@ -96,10 +132,14 @@ def self_calibration_enabled(self): be on and active for 7 days after enabling ASC, and exposed to fresh air for at least 1 hour per day. Consult the manufacturer's documentation for more information. - **NOTE**: Enabling self calibration will override any values set by specifying a - `forced_recalibration_reference` + .. note:: + Enabling self calibration will override any values set by specifying a + `forced_recalibration_reference` + + .. note:: + This value will be saved and will not be reset on boot or by calling `reset`. - **NOTE** This setting will be saved and will not be reset on boot or by calling `reset`.""" + """ return self._read_register(_CMD_AUTOMATIC_SELF_CALIBRATION) == 1 @@ -134,7 +174,11 @@ def altitude(self): this value adjusts the CO2 measurement calculations to account for the air pressure's effect on readings. - **NOTE** This value will be stored and will not be reset on boot or by calling `reset`.""" + .. note:: + This value will be saved and will not be reset on boot or by calling `reset`. + + + """ return self._read_register(_CMD_SET_ALTITUDE_COMPENSATION) @altitude.setter @@ -147,7 +191,10 @@ def temperature_offset(self): the measured signal. Value is in degrees Celsius with a resolution of 0.01 degrees and a maximum value of 655.35 C - **NOTE** This value will be saved and will not be reset on boot or by calling `reset`.""" + .. note:: + This value will be saved and will not be reset on boot or by calling `reset`. + + """ raw_offset = self._read_register(_CMD_SET_TEMPERATURE_OFFSET) return raw_offset / 100.0 @@ -156,7 +203,7 @@ def temperature_offset(self): def temperature_offset(self, offset): if offset > 655.35: raise AttributeError( - "Offset value must be less than or equal to 655.35 degrees Celcius" + "Offset value must be less than or equal to 655.35 degrees Celsius" ) self._send_command(_CMD_SET_TEMPERATURE_OFFSET, int(offset * 100)) @@ -166,8 +213,11 @@ def forced_recalibration_reference(self): """Specifies the concentration of a reference source of CO2 placed in close proximity to the sensor. The value must be from 400 to 2000 ppm. - **NOTE**: Specifying a forced recalibration reference will override any calibration values - set by Automatic Self Calibration""" + .. note:: + Specifying a forced recalibration reference will override any calibration values + set by Automatic Self Calibration + + """ return self._read_register(_CMD_SET_FORCED_RECALIBRATION_FACTOR) @forced_recalibration_reference.setter @@ -178,16 +228,22 @@ def forced_recalibration_reference(self, reference_value): def CO2(self): # pylint:disable=invalid-name """Returns the CO2 concentration in PPM (parts per million) - **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._co2 @property def temperature(self): - """Returns the current temperature in degrees celcius + """Returns the current temperature in degrees Celsius - **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._temperature @@ -196,7 +252,10 @@ 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 diff --git a/docs/examples.rst b/docs/examples.rst index 5cff903..3b467da 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -15,3 +15,12 @@ Experiment with different tuning parameters and settings .. literalinclude:: ../examples/scd30_tuning_knobs.py :caption: examples/scd30_tuning_knobs.py :linenos: + +MCP2221 and SCD30 Example +------------------------- + +MCP2221 is known to not like the SCD30. Here is how to avoid this! + +.. literalinclude:: ../examples/scd30_tuning_knobs.py + :caption: examples/scd30_tuning_knobs.py + :linenos: diff --git a/docs/index.rst b/docs/index.rst index cc66326..0f5b166 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,12 +23,12 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit SCD30 Breakout Learning Guide .. toctree:: :caption: Related Products - -* Adafruit SCD30 Breakout `_ + Adafruit SCD30 Breakout .. toctree:: :caption: Other Links diff --git a/examples/scd30_mcp2221test.py b/examples/scd30_mcp2221test.py index 22639d3..c965822 100644 --- a/examples/scd30_mcp2221test.py +++ b/examples/scd30_mcp2221test.py @@ -3,10 +3,9 @@ # SPDX-License-Identifier: Unlicense import time import board -import busio import adafruit_scd30 -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA scd = adafruit_scd30.SCD30(i2c) # The SCD30 reset generates a hiccup on the SCL and SDA lines diff --git a/examples/scd30_simpletest.py b/examples/scd30_simpletest.py index fac085e..ba3264a 100644 --- a/examples/scd30_simpletest.py +++ b/examples/scd30_simpletest.py @@ -3,10 +3,9 @@ # SPDX-License-Identifier: Unlicense import time import board -import busio import adafruit_scd30 -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA scd = adafruit_scd30.SCD30(i2c) while True: diff --git a/examples/scd30_tuning_knobs.py b/examples/scd30_tuning_knobs.py index c9c4fc6..1f44106 100644 --- a/examples/scd30_tuning_knobs.py +++ b/examples/scd30_tuning_knobs.py @@ -3,10 +3,9 @@ # SPDX-License-Identifier: Unlicense import time import board -import busio import adafruit_scd30 -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() # uses board.SCL and board.SDA scd = adafruit_scd30.SCD30(i2c) # scd.temperature_offset = 10 print("Temperature offset:", scd.temperature_offset)