npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ccs811

v1.0.4

Published

A modern library for reading data from CCS811 sensors

Downloads

26

Readme

CCS811 lib

A modern library for reading data from CCS811 sensors.

Installation

# npm users
npm install --save ccs811

# yarn users
yarn add ccs811

Typescript defintions are included.

Usage

import { initialise, pollSensor } from 'ccs811';

(async () => {
  const handle = await initialise({
    bus: 1,
    address: 0x5a,
    pollPeriodMs: 1000 // Valid values: 1000, 10000, 60000
  });

  // ... Wait a few seconds. Note that a CCS811 becomes more accurate after 48 hours of burn in.
  const reading = await pollSensor(handle);
  console.log(`CO2: ${reading.co2}ppm`);
  console.log(`VOC: ${reading.voc}ppb`);
})();

The CCS811 is more accurate if it can adjust for ambient temperature and humidity. If you have this information, use the setEnvironment call to update it periodically

// Environment is 27°C, 60% humidity
await setEnvironment(handle, 27, 60);

The polling period specified in the configuration passed to initialise() relates to how the CCS811 updates state internally. You still need to poll manually. If a new reading is available, the reading status indicates this. This flag is cleared automatically.

async function delay(ms) {
  // return await for better async stack trace support in case of errors.
  return await new Promise(resolve => setTimeout(resolve, ms));
}

while (true) {
  await delay(250);
  const reading = await pollSensor(handle);
  if (reading.status.dataReady) {
    console.log(`New CO2 reading: ${reading.co2}ppm`);
  }
}

Note that is can take several seconds after the call to initalise() for data to become available. If an error occurs, sensors have been observed to read 0xfdfd, but this is not specified in the Datasheet. Additionally, the readings prior to dataReady being set the first time will be zero and should be discarded.

Physical connections

Raspberry Pi

To connect to a Raspberry Pi:

  • 3v3 to VCC
  • GPIO2 (SDA) to SDA
  • GPIO3 (SCL) to SCL
  • GND to GND and WAK

This library was developed to operate on a Raspberry Pi. The CCS811 uses clock stretching, where it keeps the clock signal low to indicate that it needs a bit more time to complete some operation. The Raspberry Pi does not support this, but we can avoid the need if we reduce the i2c clock to 10kHz. Ensure the following is present in /boot/config.txt

# Enable i2c
dtparam=i2c_arm=o
# Reduce baud to 10Khz
dtparam=i2c_baudrate=10000

Also ensure that /etc/modules contains i2c-dev. Apart from the baudrate changes, this can all be achieved by enabling i2c using the raspi-config command line tool.

References

Datasheet