Skip to content
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

Improving Docs #14

Merged
merged 1 commit into from
Apr 24, 2021
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
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
87 changes: 73 additions & 14 deletions adafruit_scd30.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ Table of Contents
.. toctree::
:caption: Tutorials

Adafruit SCD30 Breakout Learning Guide <https://learn.adafruit.com/adafruit-scd30>

.. toctree::
:caption: Related Products


* Adafruit SCD30 Breakout <https://www.adafruit.com/product/48xx>`_
Adafruit SCD30 Breakout <https://www.adafruit.com/product/4867>

.. toctree::
:caption: Other Links
Expand Down
3 changes: 1 addition & 2 deletions examples/scd30_mcp2221test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/scd30_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions examples/scd30_tuning_knobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down