ccs811

package
v3.8.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ccs811 controls CCS811 Volatile Organic Compounds sensor via I²C interface.

Product page

https://ams.com/ccs811

Datasheet

https://ams.com/documents/20143/36005/CCS811_DS000459_7-00.pdf

Index

Constants

This section is empty.

Variables

View Source
var DefaultOpts = Opts{
	Addr:               0x5A,
	MeasurementMode:    MeasurementModeConstant1000,
	InterruptWhenReady: false,
	UseThreshold:       false,
}

DefaultOpts are the safe default options.

Functions

This section is empty.

Types

type Dev

type Dev struct {
	// contains filtered or unexported fields
}

Dev is an handle to an CCS811 sensor.

func New

func New(bus i2c.Bus, opts *Opts) (*Dev, error)

New creates a new driver for CCS811 VOC sensor.

func (*Dev) GetBaseline

func (d *Dev) GetBaseline() ([]byte, error)

GetBaseline provides current baseline used by internal measurement algorithm. For better understanding how to use this value, check the SetBaseline and documentation.

func (*Dev) GetFirmwareData

func (d *Dev) GetFirmwareData() (*FwVersions, error)

GetFirmwareData populates FwVersions structure with data.

func (*Dev) GetMeasurementModeRegister

func (d *Dev) GetMeasurementModeRegister() (MeasurementModeParams, error)

GetMeasurementModeRegister returns current measurement mode of the sensor.

func (*Dev) ReadRawData

func (d *Dev) ReadRawData() (physic.ElectricCurrent, physic.ElectricPotential, error)

ReadRawData provides current and voltage on the sensor. Current is in range of 0-63uA. Voltage is in range 0-1.65V.

func (*Dev) ReadStatus

func (d *Dev) ReadStatus() (byte, error)

ReadStatus returns value of status register.

func (*Dev) Reset

func (d *Dev) Reset() error

Reset sets device into the BOOT mode.

func (*Dev) Sense

func (d *Dev) Sense(values *SensorValues) error

Sense provides data from the sensor. This function read all 8 available bytes including error, raw data etc. If you want just eCO2 and/or VOC, use SensePartial.

func (*Dev) SensePartial

func (d *Dev) SensePartial(requested NeededData, values *SensorValues) error

SensePartial provides marginally more efficient reading from the sensor. You can specify what subset of data you want through NeededData constants.

func (*Dev) SetBaseline

func (d *Dev) SetBaseline(baseline []byte) error

SetBaseline sets current baseline for internal measurement algorithm. For more details check sensor's specification.

Manual Baseline Correction.

There is a mechanism within CCS811 to manually save and restore a previously saved baseline value using the BASELINE register. The correct time to save the baseline will depend on the customer use-case and application.

For devices which are powered for >24 hours at a time:

- During the first 500 hours – save the baseline every 24-48 hours.

- After the first 500 hours – save the baseline every 5-7 days.

For devices which are powered <24 hours at a time:

- If the device is run in, save the baseline before power down.

- If multiple operating modes are used, a separate baseline should be stored for each.

- The baseline should only be restored when the resistance is stable (typically 20-30 minutes).

- If changing from a low to high power mode (without spending at least 10 minutes in idle), the sensor resistance should be allowed to settle again before restoring the baseline.

Note(s):

1) If a value is written to the BASELINE register while the sensor is stabilising, the output of the TVOC and eCO2 calculations may be higher than expected.

2) The baseline must be written after the conditioning period

func (*Dev) SetEnvironmentData

func (d *Dev) SetEnvironmentData(temp, humidity float32) error

SetEnvironmentData allows to provide temperature and humidity so sensor can compensate it's measurement.

func (*Dev) SetMeasurementModeRegister

func (d *Dev) SetMeasurementModeRegister(mmp MeasurementModeParams) error

SetMeasurementModeRegister sets one of the 5 measurement modes, interrupt generation and interrupt threshold.

func (*Dev) StartSensorApp

func (d *Dev) StartSensorApp() error

StartSensorApp initializes sensor to application mode.

func (*Dev) String

func (d *Dev) String() string

type FwVersions

type FwVersions struct {
	HWIdentifier       byte
	HWVersion          byte
	BootVersion        string
	ApplicationVersion string
}

FwVersions is a strcutre which aggregates all different versions of sensors features.

HWIdentifier - for family of CCS81x should be 0x81.

HWVersion - hardware major and minor version: 0x1X.

BootVersion - version of firmware bootloader in form Major.Minor.Trivial.

ApplicationVersion - version of firmware application in form Major.Minor.Trivial.

type MeasurementMode

type MeasurementMode byte

MeasurementMode represents different ways how data is read

const (
	MeasurementModeIdle         MeasurementMode = 0
	MeasurementModeConstant1000 MeasurementMode = 1
	MeasurementModePulse        MeasurementMode = 2
	MeasurementModeLowPower     MeasurementMode = 3
	MeasurementModeConstant250  MeasurementMode = 4
)

Different measurement mode constants:

- Mode 0: Idle, low current mode.

- Mode 1: Constant power mode, IAQ measurement every second.

- Mode 2: Pulse heating mode IAQ measurement every 10 seconds.

- Mode 3: Low power pulse heating mode IAQ measurement every 60 seconds.

- Mode 4: Constant power mode, sensor measurement every 250ms.

type MeasurementModeParams

type MeasurementModeParams struct {
	MeasurementMode   MeasurementMode
	GenerateInterrupt bool // True if sensor should generate interrupts on new measurement.
	UseThreshold      bool // True if sensor should use thresholds from threshold register.
}

MeasurementModeParams is a structure representing Measuremode register of the sensor.

type NeededData

type NeededData byte

NeededData represents set of data read from the sensor.

const (
	ReadCO2          NeededData = 2
	ReadCO2VOC       NeededData = 4
	ReadCO2VOCStatus NeededData = 5
	ReadAll          NeededData = 8
)

What data should be read from the sensor.

type Opts

type Opts struct {
	Addr               uint16
	MeasurementMode    MeasurementMode
	InterruptWhenReady bool
	UseThreshold       bool
}

Opts holds the configuration options. The address must be 0x5A or 0x5B.

type SensorErrorID

type SensorErrorID byte

SensorErrorID represents error reported by the sensor.

type SensorValues

type SensorValues struct {
	ECO2           int
	VOC            int
	Status         byte
	Error          error
	RawDataCurrent physic.ElectricCurrent
	RawDataVoltage physic.ElectricPotential
}

SensorValues represents data read from the sensor. Data are populated based on NeededData parameter.

Sensor provides eCO2 measurement in range: 400ppm to 8192ppm, and VOC measurement in range: 0ppb to 1187ppb.

Sensing resistor's current is between 0-63uA, and voltage 0-1.65V.

Status represents sensor's status register.

1001 0110
|||||||||
||||||| \- 1 = There is an error.
|||||| \- Reserved.
||||| \- Reserved.
|||| \- 1 = Data ready.
||| \- 1 = Valid application firmware loaded.
|| \- Reserved.
| \- Reserved.
 \- 0 = Firmware in boot mode, 1 Firmware in application mode.

Error represents error state of the sensor if available, otherwise is nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL