Python-ify the API, setup docs and add the example.
This commit is contained in:
parent
02c90b18f2
commit
387bf909ca
11 changed files with 655 additions and 170 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
_build
|
||||
*.pyc
|
||||
*.mpy
|
||||
54
.travis.yml
Normal file
54
.travis.yml
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# Travis CI configuration for automated .mpy file generation.
|
||||
# Author: Tony DiCola
|
||||
# License: Public Domain
|
||||
# This configuration will work with Travis CI (travis-ci.org) to automacially
|
||||
# build .mpy files for MicroPython when a new tagged release is created. This
|
||||
# file is relatively generic and can be shared across multiple repositories by
|
||||
# following these steps:
|
||||
# 1. Copy this file into a .travis.yml file in the root of the repository.
|
||||
# 2. Change the deploy > file section below to list each of the .mpy files
|
||||
# that should be generated. The config will automatically look for
|
||||
# .py files with the same name as the source for generating the .mpy files.
|
||||
# Note that the .mpy extension should be lower case!
|
||||
# 3. Commit the .travis.yml file and push it to GitHub.
|
||||
# 4. Go to travis-ci.org and find the repository (it needs to be setup to access
|
||||
# your github account, and your github account needs access to write to the
|
||||
# repo). Flip the 'ON' switch on for Travis and the repo, see the Travis
|
||||
# docs for more details: https://docs.travis-ci.com/user/getting-started/
|
||||
# 5. Get a GitHub 'personal access token' which has at least 'public_repo' or
|
||||
# 'repo' scope: https://help.github.com/articles/creating-an-access-token-for-command-line-use/
|
||||
# Keep this token safe and secure! Anyone with the token will be able to
|
||||
# access and write to your GitHub repositories. Travis will use the token
|
||||
# to attach the .mpy files to the release.
|
||||
# 6. In the Travis CI settings for the repository that was enabled find the
|
||||
# environment variable editing page: https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings
|
||||
# Add an environment variable named GITHUB_TOKEN and set it to the value
|
||||
# of the GitHub personal access token above. Keep 'Display value in build
|
||||
# log' flipped off.
|
||||
# 7. That's it! Tag a release and Travis should go to work to add .mpy files
|
||||
# to the release. It takes about a 2-3 minutes for a worker to spin up,
|
||||
# build mpy-cross, and add the binaries to the release.
|
||||
language: generic
|
||||
|
||||
sudo: true
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key: $GITHUB_TOKEN
|
||||
file:
|
||||
- "adafruit_pcf8523.mpy"
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
||||
|
||||
before_install:
|
||||
- sudo apt-get -yqq update
|
||||
- sudo apt-get install -y build-essential git python python-pip
|
||||
- git clone https://github.com/adafruit/micropython.git
|
||||
- make -C micropython/mpy-cross
|
||||
- export PATH=$PATH:$PWD/micropython/mpy-cross/
|
||||
- sudo pip install shyaml
|
||||
|
||||
before_deploy:
|
||||
- shyaml get-values deploy.file < .travis.yml | sed 's/.mpy/.py/' | xargs -L1 mpy-cross
|
||||
|
||||
|
|
@ -21,27 +21,17 @@
|
|||
# THE SOFTWARE.
|
||||
|
||||
"""
|
||||
`Adafruit_CCS811` - CCS811 air quality sensor
|
||||
`CCS811` - CCS811 air quality sensor
|
||||
====================================================
|
||||
This library supports the use of the CCS811 in CircuitPython. This base
|
||||
class is inherited by the chip-specific subclasses.
|
||||
Functions are included for reading and writing registers and manipulating
|
||||
datetime objects.
|
||||
Author(s): Dean Miller for Adafruit Industries.
|
||||
Date: June 2017
|
||||
Affiliation: Adafruit Industries
|
||||
Implementation Notes
|
||||
--------------------
|
||||
**Hardware:**
|
||||
*
|
||||
**Software and Dependencies:**
|
||||
* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: https://github.com/adafruit/micropython/releases
|
||||
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
|
||||
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
|
||||
**Notes:**
|
||||
#. Datasheet:
|
||||
"""
|
||||
This library supports the use of the CCS811 air quality sensor in CircuitPython.
|
||||
|
||||
Author(s): Dean Miller for Adafruit Industries
|
||||
|
||||
**Notes:**
|
||||
|
||||
#. `Datasheet <https://cdn-learn.adafruit.com/assets/assets/000/044/636/original/CCS811_DS000459_2-00-1098798.pdf?1501602769>`_
|
||||
"""
|
||||
from micropython import const
|
||||
from adafruit_bus_device.i2c_device import I2CDevice
|
||||
from adafruit_register import i2c_bit
|
||||
from adafruit_register import i2c_bits
|
||||
|
|
@ -54,23 +44,19 @@ CCS811_ENV_DATA = const(0x05)
|
|||
CCS811_NTC = const(0x06)
|
||||
CCS811_THRESHOLDS = const(0x10)
|
||||
|
||||
'''
|
||||
CCS811_BASELINE = 0x11
|
||||
CCS811_HW_ID = 0x20
|
||||
CCS811_HW_VERSION = 0x21
|
||||
CCS811_FW_BOOT_VERSION = 0x23
|
||||
CCS811_FW_APP_VERSION = 0x24
|
||||
CCS811_ERROR_ID = 0xE0
|
||||
'''
|
||||
# CCS811_BASELINE = 0x11
|
||||
# CCS811_HW_ID = 0x20
|
||||
# CCS811_HW_VERSION = 0x21
|
||||
# CCS811_FW_BOOT_VERSION = 0x23
|
||||
# CCS811_FW_APP_VERSION = 0x24
|
||||
# CCS811_ERROR_ID = 0xE0
|
||||
|
||||
CCS811_SW_RESET = const(0xFF)
|
||||
|
||||
'''
|
||||
CCS811_BOOTLOADER_APP_ERASE = 0xF1
|
||||
CCS811_BOOTLOADER_APP_DATA = 0xF2
|
||||
CCS811_BOOTLOADER_APP_VERIFY = 0xF3
|
||||
CCS811_BOOTLOADER_APP_START = 0xF4
|
||||
'''
|
||||
# CCS811_BOOTLOADER_APP_ERASE = 0xF1
|
||||
# CCS811_BOOTLOADER_APP_DATA = 0xF2
|
||||
# CCS811_BOOTLOADER_APP_VERIFY = 0xF3
|
||||
# CCS811_BOOTLOADER_APP_START = 0xF4
|
||||
|
||||
CCS811_DRIVE_MODE_IDLE = const(0x00)
|
||||
CCS811_DRIVE_MODE_1SEC = const(0x01)
|
||||
|
|
@ -81,124 +67,106 @@ CCS811_DRIVE_MODE_250MS = const(0x04)
|
|||
CCS811_HW_ID_CODE = const(0x81)
|
||||
CCS811_REF_RESISTOR = const(100000)
|
||||
|
||||
class Adafruit_CCS811:
|
||||
class CCS811:
|
||||
"""CCS811 gas sensor driver.
|
||||
|
||||
:param ~busio.I2C i2c: The I2C bus.
|
||||
:param int addr: The I2C address of the CCS811.
|
||||
"""
|
||||
#set up the registers
|
||||
#self.status = Adafruit_bitfield([('ERROR' , 1), ('unused', 2), ('DATA_READY' , 1), ('APP_VALID', 1), ('unused2' , 2), ('FW_MODE' , 1)])
|
||||
error = i2c_bit.ROBit(0x00, 0)
|
||||
"""True when an error has occured."""
|
||||
data_ready = i2c_bit.ROBit(0x00, 3)
|
||||
"""True when new data has been read."""
|
||||
app_valid = i2c_bit.ROBit(0x00, 4)
|
||||
fw_mode = i2c_bit.ROBit(0x00, 7)
|
||||
|
||||
hw_id = i2c_bits.ROBits(8, 0x20, 0)
|
||||
|
||||
#self.meas_mode = Adafruit_bitfield([('unused', 2), ('INT_THRESH', 1), ('INT_DATARDY', 1), ('DRIVE_MODE', 3)])
|
||||
int_thresh = i2c_bit.RWBit(0x01, 2)
|
||||
interrupt_enabled = i2c_bit.RWBit(0x01, 3)
|
||||
drive_mode = i2c_bits.RWBits(3, 0x01, 4)
|
||||
|
||||
#self.error_id = Adafruit_bitfield([('WRITE_REG_INVALID', 1), ('READ_REG_INVALID', 1), ('MEASMODE_INVALID', 1), ('MAX_RESISTANCE', 1), ('HEATER_FAULT', 1), ('HEATER_SUPPLY', 1)])
|
||||
|
||||
TVOC = 0
|
||||
eCO2 = 0
|
||||
|
||||
tempOffset = 0.0
|
||||
temp_offset = 0.0
|
||||
"""Temperature offset."""
|
||||
|
||||
def __init__(self, i2c, addr=0x5A):
|
||||
self.i2c_device = I2CDevice(i2c, addr)
|
||||
|
||||
#check that the HW id is correct
|
||||
#check that the HW id is correct
|
||||
if self.hw_id != CCS811_HW_ID_CODE:
|
||||
raise RuntimeError("Device ID returned is not correct! Please check your wiring.")
|
||||
|
||||
|
||||
#try to start the app
|
||||
buf = bytearray(1)
|
||||
buf[0] = 0xF4
|
||||
self.i2c_device.write(buf, end=1, stop=True)
|
||||
with self.i2c_device as i2c:
|
||||
i2c.write(buf, end=1, stop=True)
|
||||
time.sleep(.1)
|
||||
|
||||
|
||||
#make sure there are no errors and we have entered application mode
|
||||
if self.checkError():
|
||||
raise RuntimeError("Device returned an Error! Try removing and reapplying power to the device and running the code again.")
|
||||
if self.error:
|
||||
raise RuntimeError("Device returned a error! Try removing and reapplying power to the device and running the code again.")
|
||||
if not self.fw_mode:
|
||||
raise RuntimeError("Device did not enter application mode! If you got here, there may be a problem with the firmware on your sensor.")
|
||||
|
||||
|
||||
self.interrupt_enabled = False
|
||||
|
||||
|
||||
#default to read every second
|
||||
self.setDriveMode(CCS811_DRIVE_MODE_1SEC)
|
||||
self.drive_mode = CCS811_DRIVE_MODE_1SEC
|
||||
|
||||
self._eCO2 = None
|
||||
self._TVOC = None
|
||||
|
||||
def setDriveMode(self, mode):
|
||||
self.drive_mode = mode
|
||||
@property
|
||||
def error_code(self):
|
||||
"""Error code"""
|
||||
buf = bytearray(2)
|
||||
buf[0] = 0xE0
|
||||
with self.i2c_device as i2c:
|
||||
i2c.write(buf, end=1, stop=False)
|
||||
i2c.read_into(buf, start=1)
|
||||
return buf[1]
|
||||
|
||||
|
||||
def available(self):
|
||||
return self.data_ready
|
||||
|
||||
|
||||
def readData(self):
|
||||
|
||||
if not self.data_ready:
|
||||
return False
|
||||
else:
|
||||
def _update_data(self):
|
||||
if self.data_ready:
|
||||
buf = bytearray(9)
|
||||
buf[0] = CCS811_ALG_RESULT_DATA
|
||||
self.i2c_device.write(buf, end=1, stop=False)
|
||||
self.i2c_device.read_into(buf, start=1)
|
||||
with self.i2c_device as i2c:
|
||||
i2c.write(buf, end=1, stop=False)
|
||||
i2c.read_into(buf, start=1)
|
||||
|
||||
self._eCO2 = (buf[1] << 8) | (buf[2])
|
||||
self._TVOC = (buf[3] << 8) | (buf[4])
|
||||
|
||||
self.eCO2 = (buf[1] << 8) | (buf[2])
|
||||
self.TVOC = (buf[3] << 8) | (buf[4])
|
||||
|
||||
if self.error:
|
||||
return buf[6]
|
||||
|
||||
else:
|
||||
return 0
|
||||
|
||||
raise RuntimeError("Error:" + str(self.error_code))
|
||||
|
||||
@property
|
||||
def TVOC(self):
|
||||
"""Total Volatile Organic Compound in parts per billion."""
|
||||
self._update_data()
|
||||
return self._TVOC
|
||||
|
||||
def setEnvironmentalData(self, humidity, temperature):
|
||||
@property
|
||||
def eCO2(self):
|
||||
"""Equivalent Carbon Dioxide in parts per million. Clipped to 400 to 8192ppm."""
|
||||
return self._eCO2
|
||||
|
||||
''' Humidity is stored as an unsigned 16 bits in 1/512%RH. The
|
||||
default value is 50% = 0x64, 0x00. As an example 48.5%
|
||||
humidity would be 0x61, 0x00.'''
|
||||
|
||||
''' Temperature is stored as an unsigned 16 bits integer in 1/512
|
||||
degrees there is an offset: 0 maps to -25C. The default value is
|
||||
25C = 0x64, 0x00. As an example 23.5% temperature would be
|
||||
0x61, 0x00.
|
||||
The internal algorithm uses these values (or default values if
|
||||
not set by the application) to compensate for changes in
|
||||
relative humidity and ambient temperature.'''
|
||||
|
||||
hum_perc = humidity << 1
|
||||
|
||||
parts = math.fmod(temperature)
|
||||
fractional = parts[0]
|
||||
temperature = parts[1]
|
||||
|
||||
temp_high = ((temperature + 25) << 9)
|
||||
temp_low = ((fractional / 0.001953125) & 0x1FF)
|
||||
|
||||
temp_conv = (temp_high | temp_low)
|
||||
|
||||
buf = bytearray([CCS811_ENV_DATA, hum_perc, 0x00,((temp_conv >> 8) & 0xFF), (temp_conv & 0xFF)])
|
||||
|
||||
self.i2c_device.write(buf)
|
||||
|
||||
|
||||
|
||||
#calculate temperature based on the NTC register
|
||||
def calculateTemperature(self):
|
||||
@property
|
||||
def temperature(self):
|
||||
"""Temperature based on optional thermistor in Celsius."""
|
||||
buf = bytearray(5)
|
||||
buf[0] = CCS811_NTC
|
||||
self.i2c_device.write(buf, end=1, stop=False)
|
||||
self.i2c_device.read_into(buf, start=1)
|
||||
with self.i2c_device as i2c:
|
||||
i2c.write(buf, end=1, stop=False)
|
||||
i2c.read_into(buf, start=1)
|
||||
|
||||
vref = (buf[1] << 8) | buf[2]
|
||||
vntc = (buf[3] << 8) | buf[4]
|
||||
|
||||
#from ams ccs811 app note
|
||||
# From ams ccs811 app note 000925
|
||||
# https://download.ams.com/content/download/9059/13027/version/1/file/CCS811_Doc_cAppNote-Connecting-NTC-Thermistor_AN000372_v1..pdf
|
||||
rntc = float(vntc) * CCS811_REF_RESISTOR / float(vref)
|
||||
|
||||
ntc_temp = math.log(rntc / 10000.0)
|
||||
|
|
@ -206,20 +174,50 @@ class Adafruit_CCS811:
|
|||
ntc_temp += 1.0 / (25 + 273.15)
|
||||
ntc_temp = 1.0 / ntc_temp
|
||||
ntc_temp -= 273.15
|
||||
return ntc_temp - self.tempOffset
|
||||
return ntc_temp - self.temp_offset
|
||||
|
||||
def set_environmental_data(self, humidity, temperature):
|
||||
"""Set the temperature and humidity used when computing eCO2 and TVOC values.
|
||||
|
||||
def setThresholds(self, low_med, med_high, hysteresis):
|
||||
:param int humidity: The current relative humidity in percent.
|
||||
:param float temperature: The current temperature in Celsius."""
|
||||
# Humidity is stored as an unsigned 16 bits in 1/512%RH. The default
|
||||
# value is 50% = 0x64, 0x00. As an example 48.5% humidity would be 0x61,
|
||||
# 0x00.
|
||||
hum_perc = int(humidity) << 1
|
||||
|
||||
# Temperature is stored as an unsigned 16 bits integer in 1/512 degrees
|
||||
# there is an offset: 0 maps to -25C. The default value is 25C = 0x64,
|
||||
# 0x00. As an example 23.5% temperature would be 0x61, 0x00.
|
||||
parts = math.fmod(temperature)
|
||||
fractional = parts[0]
|
||||
temperature = parts[1]
|
||||
|
||||
temp_high = ((temperature + 25) << 9)
|
||||
temp_low = ((fractional / 0.001953125) & 0x1FF)
|
||||
|
||||
temp_conv = (temp_high | temp_low)
|
||||
|
||||
buf = bytearray([CCS811_ENV_DATA, hum_perc, 0x00,((temp_conv >> 8) & 0xFF), (temp_conv & 0xFF)])
|
||||
|
||||
with self.i2c_device as i2c:
|
||||
i2c.write(buf)
|
||||
|
||||
def set_interrupt_thresholds(self, low_med, med_high, hysteresis):
|
||||
"""Set the thresholds used for triggering the interrupt based on eCO2.
|
||||
The interrupt is triggered when the value crossed a boundary value by the
|
||||
minimum hysteresis value.
|
||||
|
||||
:param int low_med: Boundary between low and medium ranges
|
||||
:param int med_high: Boundary between medium and high ranges
|
||||
:param int hysteresis: Minimum difference between reads"""
|
||||
buf = bytearray([CCS811_THRESHOLDS, ((low_med >> 8) & 0xF), (low_med & 0xF), ((med_high >> 8) & 0xF), (med_high & 0xF), hysteresis ])
|
||||
self.i2c_device.write(buf)
|
||||
|
||||
|
||||
def SWReset(self):
|
||||
with self.i2c_device as i2c:
|
||||
self.i2c_device.write(buf)
|
||||
|
||||
def reset(self):
|
||||
"""Initiate a software reset."""
|
||||
#reset sequence from the datasheet
|
||||
seq = bytearray([CCS811_SW_RESET, 0x11, 0xE5, 0x72, 0x8A])
|
||||
self.i2c_device.write(seq)
|
||||
|
||||
|
||||
def checkError(self):
|
||||
return self.error
|
||||
with self.i2c_device as i2c:
|
||||
self.i2c_device.write(seq)
|
||||
|
|
|
|||
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Dean Miller
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
51
README.md
51
README.md
|
|
@ -1,51 +0,0 @@
|
|||
# Adafruit_CircuitPython_CCS811
|
||||
circuit python driver for CCS811 air quality sensor
|
||||
# Dependencies
|
||||
|
||||
This driver depends on the Register and Bus Device libraries. Please ensure they are also available on the CircuitPython filesystem. This is easily achieved by downloading a library and driver bundle.
|
||||
|
||||
# Usage Notes
|
||||
|
||||
see here for wiring and installation instructions:
|
||||
https://learn.adafruit.com/ccs811-air-quality-sensor/circuit-python-example
|
||||
|
||||
Of course, you must import the library to use it:
|
||||
|
||||
```
|
||||
import busio
|
||||
import Adafruit_CCS811
|
||||
```
|
||||
The way to create an I2C object depends on the board you are using. For boards with labeled SCL and SDA pins, you can:
|
||||
|
||||
```
|
||||
from board import *
|
||||
```
|
||||
|
||||
You can also use pins defined by the onboard microcontroller through the microcontroller.pin module.
|
||||
|
||||
Now, to initialize the I2C bus:
|
||||
|
||||
```
|
||||
myI2C = busio.I2C(SCL, SDA)
|
||||
```
|
||||
|
||||
Once you have created the I2C interface object, you can use it to instantiate the CCS811 object
|
||||
|
||||
```
|
||||
ccs = Adafruit_CCS811.Adafruit_CCS811(myI2C)
|
||||
```
|
||||
|
||||
# Reading Sensor
|
||||
|
||||
To read the gas sensor and thermistor you can do the following:
|
||||
|
||||
```
|
||||
if ccs.data_ready:
|
||||
temp = ccs.calculateTemperature()
|
||||
if not ccs.readData():
|
||||
print("CO2: ", ccs.eCO2, " TVOC:", ccs.TVOC, " temp:", temp)
|
||||
else:
|
||||
print("ERROR!")
|
||||
while(1):
|
||||
pass
|
||||
```
|
||||
69
README.rst
Normal file
69
README.rst
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
|
||||
Adafruit CircuitPython CCS811 Library
|
||||
=====================================
|
||||
|
||||
.. image:: https://readthedocs.org/projects/adafruit-circuitpython-ccs811/badge/?version=latest
|
||||
:target: https://circuitpython.readthedocs.io/projects/ccs811/en/latest/
|
||||
:alt: Documentation Status
|
||||
|
||||
.. image :: https://img.shields.io/discord/327254708534116352.svg
|
||||
:target: https://adafru.it/discord
|
||||
:alt: Discord
|
||||
|
||||
CircuitPython driver for the `CCS811 air quality sensor <https://www.adafruit.com/product/3566>`_.
|
||||
|
||||
Dependencies
|
||||
=============
|
||||
This driver depends on:
|
||||
|
||||
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
|
||||
* `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
|
||||
* `Register <https://github.com/adafruit/Adafruit_CircuitPython_Register>`_
|
||||
|
||||
Please ensure all dependencies are available on the CircuitPython filesystem.
|
||||
This is easily achieved by downloading
|
||||
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
|
||||
|
||||
Usage Notes
|
||||
===========
|
||||
|
||||
See `the guide <https://learn.adafruit.com/ccs811-air-quality-sensor/circuit-python-example>`_
|
||||
for wiring and installation instructions.
|
||||
|
||||
Of course, you must import the library to use it:
|
||||
|
||||
.. code:: python
|
||||
|
||||
import busio
|
||||
import adafruit_CCS811
|
||||
|
||||
Next, initialize the I2C bus object.
|
||||
|
||||
.. code:: python
|
||||
|
||||
from board import *
|
||||
myI2C = busio.I2C(SCL, SDA)
|
||||
|
||||
Once you have created the I2C interface object, you can use it to instantiate
|
||||
the CCS811 object
|
||||
|
||||
.. code:: python
|
||||
|
||||
ccs = adafruit_ccs811.CCS811(myI2C)
|
||||
|
||||
Reading Sensor
|
||||
--------------
|
||||
|
||||
To read the gas sensor and temperature simply read the attributes:
|
||||
|
||||
.. code:: python
|
||||
|
||||
print("CO2: ", ccs.eCO2, " TVOC:", ccs.TVOC, " temp:", ccs.temperature)
|
||||
|
||||
API Reference
|
||||
=============
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
api
|
||||
3
api.rst
Normal file
3
api.rst
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
.. automodule:: adafruit_ccs811
|
||||
:members:
|
||||
365
conf.py
Normal file
365
conf.py
Normal file
|
|
@ -0,0 +1,365 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Adafruit's CCS811 Library documentation build configuration file, created by
|
||||
# sphinx-quickstart on Fri Nov 11 21:37:36 2016.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its
|
||||
# containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#
|
||||
# needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.todo',
|
||||
'sphinx.ext.viewcode',
|
||||
'sphinx.ext.intersphinx'
|
||||
]
|
||||
|
||||
autodoc_mock_imports = []
|
||||
|
||||
# Mock out micropython ourselves.
|
||||
import imp
|
||||
m = imp.new_module("micropython")
|
||||
m.const = lambda x: x
|
||||
sys.modules["micropython"] = m
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix(es) of source filenames.
|
||||
# You can specify multiple suffix as a list of string:
|
||||
#
|
||||
source_suffix = ['.rst', '.md']
|
||||
# source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#
|
||||
# source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'README'
|
||||
|
||||
# General information about the project.
|
||||
project = u'Adafruit\'s CCS811 Library'
|
||||
copyright = u'2016, Dean Miller, Scott Shawcroft'
|
||||
author = u'Dean Miller, Scott Shawcroft'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = u'1.0'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = u'1.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#
|
||||
# This is also used if you do content translation via gettext catalogs.
|
||||
# Usually you set "language" from the command line for these cases.
|
||||
language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#
|
||||
# today = ''
|
||||
#
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
#
|
||||
# today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This patterns also effect to html_static_path and html_extra_path
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
#
|
||||
default_role = "any"
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#
|
||||
# add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
#
|
||||
# add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#
|
||||
# show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
# modindex_common_prefix = []
|
||||
|
||||
# If true, keep warnings as "system message" paragraphs in the built documents.
|
||||
# keep_warnings = False
|
||||
|
||||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
||||
todo_include_todos = True
|
||||
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
|
||||
|
||||
if not on_rtd: # only import and set the theme if we're building docs locally
|
||||
try:
|
||||
import sphinx_rtd_theme
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
|
||||
except:
|
||||
html_theme = 'default'
|
||||
html_theme_path = ['.']
|
||||
else:
|
||||
html_theme_path = ['.']
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#
|
||||
# html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
# html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents.
|
||||
# "<project> v<release> documentation" by default.
|
||||
#
|
||||
# html_title = u'Adafruit\'s CCS811 Library v1.0'
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
#
|
||||
# html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
#
|
||||
# html_logo = None
|
||||
|
||||
# The name of an image file (relative to this directory) to use as a favicon of
|
||||
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#
|
||||
# html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# Add any extra paths that contain custom files (such as robots.txt or
|
||||
# .htaccess) here, relative to this directory. These files are copied
|
||||
# directly to the root of the documentation.
|
||||
#
|
||||
# html_extra_path = []
|
||||
|
||||
# If not None, a 'Last updated on:' timestamp is inserted at every page
|
||||
# bottom, using the given strftime format.
|
||||
# The empty string is equivalent to '%b %d, %Y'.
|
||||
#
|
||||
# html_last_updated_fmt = None
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
#
|
||||
# html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#
|
||||
# html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
#
|
||||
# html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#
|
||||
# html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
#
|
||||
# html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
#
|
||||
# html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
#
|
||||
# html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
#
|
||||
# html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
#
|
||||
# html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
#
|
||||
# html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
# html_file_suffix = None
|
||||
|
||||
# Language to be used for generating the HTML full-text search index.
|
||||
# Sphinx supports the following languages:
|
||||
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja'
|
||||
# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr', 'zh'
|
||||
#
|
||||
# html_search_language = 'en'
|
||||
|
||||
# A dictionary with options for the search language support, empty by default.
|
||||
# 'ja' uses this config value.
|
||||
# 'zh' user can custom change `jieba` dictionary path.
|
||||
#
|
||||
# html_search_options = {'type': 'default'}
|
||||
|
||||
# The name of a javascript file (relative to the configuration directory) that
|
||||
# implements a search results scorer. If empty, the default will be used.
|
||||
#
|
||||
# html_search_scorer = 'scorer.js'
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
# htmlhelp_basename = 'AdafruitsCCS811Librarydoc'
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#
|
||||
# 'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#
|
||||
# 'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#
|
||||
# 'preamble': '',
|
||||
|
||||
# Latex figure (float) alignment
|
||||
#
|
||||
# 'figure_align': 'htbp',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(master_doc, 'AdafruitsCCS811Library.tex', u'Adafruit\'s CCS811 Library Documentation',
|
||||
u'Dean Miller, Scott Shawcroft', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
#
|
||||
# latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#
|
||||
# latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#
|
||||
# latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#
|
||||
# latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#
|
||||
# latex_appendices = []
|
||||
|
||||
# It false, will not define \strong, \code, itleref, \crossref ... but only
|
||||
# \sphinxstrong, ..., \sphinxtitleref, ... To help avoid clash with user added
|
||||
# packages.
|
||||
#
|
||||
# latex_keep_old_macro_names = True
|
||||
|
||||
# If false, no module index is generated.
|
||||
#
|
||||
# latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
(master_doc, 'AdafruitsCCS811Library23library', u'Adafruit\'s CCS811 Library Documentation',
|
||||
[author], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#
|
||||
# man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'AdafruitsCCS811Library', u'Adafruit\'s CCS811 Library Documentation',
|
||||
author, 'AdafruitsCCS811Library', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#
|
||||
# texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#
|
||||
# texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
#
|
||||
# texinfo_show_urls = 'footnote'
|
||||
|
||||
# If true, do not generate a @detailmenu in the "Top" node's menu.
|
||||
#
|
||||
# texinfo_no_detailmenu = False
|
||||
|
||||
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),
|
||||
'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
|
||||
19
example/code.py
Normal file
19
example/code.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from board import *
|
||||
import time
|
||||
import busio
|
||||
|
||||
import adafruit_CCS811
|
||||
|
||||
myI2C = busio.I2C(SCL, SDA)
|
||||
|
||||
ccs = adafruit_CCS811.CCS811(myI2C)
|
||||
|
||||
#wait for the sensor to be ready and calibrate the thermistor
|
||||
while not ccs.data_ready:
|
||||
pass
|
||||
temp = ccs.temperature
|
||||
ccs.temp_offset = temp - 25.0
|
||||
|
||||
while True:
|
||||
print("CO2: ", ccs.eCO2, " TVOC:", ccs.TVOC, " temp:", ccs.temperature)
|
||||
time.sleep(.5)
|
||||
2
readthedocs.yml
Normal file
2
readthedocs.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
requirements_file: requirements.txt
|
||||
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
adafruit-circuitpython-register
|
||||
adafruit-circuitpython-bus-device>=0.2.0
|
||||
Loading…
Reference in a new issue