Giter Club home page Giter Club logo

scd30-node's Introduction

scd30-node

Node.js library for Sensirion SCD30, the CO2, temperature, and humidity sensor.

The library exposes all of the commands supported by the SCD30, as documented in the official Interface Description.

Uses i2c-bus for connection to the SCD30.

Usage

yarn add scd30-node
const {SCD30} = require('scd30-node');

(async () => {
  const scd30 = await SCD30.connect();
  await scd30.startContinuousMeasurement();

  const measurement = await scd30.readMeasurement();
  console.log(`CO2 Concentration: ${measurement.co2Concentration} ppm`);
  console.log(`Temperature: ${measurement.temperature} °C`);
  console.log(`Humidity: ${measurement.relativeHumidity} %`);

  await scd30.disconnect();
})();

API Documentation

Class SCD30

public static connect(busNumber: number = DEFAULT_I2C_BUS_NUMBER): Promise<SCD30>

Connects to the SCD30 on the given I2C bus. Default bus number is 1.

isDataReady(): Promise<boolean>

Used to determine if a measurement can be read from the sensor's buffer. Whenever there is a measurement available from the internal buffer this function returns true, and false otherwise. As soon as the measurement has been read, the return value changes to false. It is recommended to call this function before calling readMeasurement.

readMeasurement(): Promise<Measurement>

Read a measurement of CO2 concentration, temperature, and humidity. Returns the measurement as an object:

{
  co2Concentration: number;
  temperature: number;
  relativeHumidity: number;
}

startContinuousMeasurement(pressure: number = 0): Promise<void>

Starts continuous measurement of CO2 concentration, temperature, and humidity. Measurement data which is not read from the sensor will be overwritten. The measurement interval is adjustable via setMeasurementInterval, initial measurement rate is 2s.

stopContinuousMeasurement(): Promise<void>

Stops continuous measurement.

getMeasurementInterval(): Promise<number>

Returns current interval of continuous measurement.

setMeasurementInterval(interval: number): Promise<void>

Sets the interval of continuous measurement. Initial value is 2s. The chosen measurement interval is saved in non-volatile memory and thus is not reset to its initial value after power up.

setAutomaticSelfCalibration(enable?: boolean): Promise<void>

Activates or deactivates automatic self-calibration.

isAutomaticSelfCalibrationActive(): Promise<boolean>

Indicates whether automatic self-calibration is active.

setForcedRecalibrationValue(co2ppm: number): Promise<void>

Forced recalibration (FRC) is used to compensate for sensor drifts when a reference value of CO2 concentration in close proximity to the SCD30 is available. For best results, the sensor has to be run in a stable environment in continuous mode at a measurement rate of 2s for at least two minutes before applying the FRC command and sending the reference value.

getForcedRecalibrationValue(): Promise<number>

Returns the most recently used reference value of FRC. After repowering the sensor, the command will return the standard reference value of 400 ppm.

setTemperatureOffset(offset: number): Promise<void>

The on-board RH/T sensor is influenced by thermal self-heating of SCD30 and other electrical components. Design-in alters the thermal properties of SCD30 such that temperature and humidity offsets may occur when operating the sensor in end-customer devices. Compensation of those effects is achievable by writing the temperature offset found in continuous operation of the device into the sensor.

getTemperatureOffset(): Promise<number>

Returns the temperature offset.

setAltitudeCompensation(altitude: number): Promise<void>

Measurements of CO2 concentration based on the NDIR principle are influenced by altitude. SCD30 can compensate deviations due to altitude. Setting altitude is disregarded when an ambient pressure was provided in startContinuousMeasurement.

getAltitudeCompensation(): Promise<number>

Returns the altitude compensation value in meters.

getFirmwareVersion(): Promise<string>

Returns the firmware version of SCD30.

softReset(): Promise<void>

Perform soft reset.

disconnect(): Promise<void>

Close the I2C bus.

scd30-node's People

Contributors

dependabot[bot] avatar rsmeral avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

bakon11 buuhuu

scd30-node's Issues

can not run in Rpi3

pi@raspberrypi:~/m $ node index.js
/home/pi/m/index.js:1
import {SCD30} from 'scd30-node';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:1072:16)
at Module._compile (internal/modules/cjs/loader.js:1122:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
pi@raspberrypi:~/m $ nodejs index.js
/home/pi/m/index.js:1
(function (exports, require, module, __filename, __dirname) { import {SCD30} from 'scd30-node';
^

SyntaxError: Unexpected token {
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.