scd30-node
v1.0.4
Published
Node.js library for [Sensirion SCD30]( https://www.sensirion.com/products/catalog/SCD30), the CO2, temperature, and humidity sensor.
Downloads
141
Readme
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
- connect
- isDataReady
- readMeasurement
- startContinuousMeasurement
- stopContinuousMeasurement
- getMeasurementInterval
- setMeasurementInterval
- setAutomaticSelfCalibration
- isAutomaticSelfCalibrationActive
- setForcedRecalibrationValue
- getForcedRecalibrationValue
- setTemperatureOffset
- getTemperatureOffset
- setAltitudeCompensation
- getAltitudeCompensation
- getFirmwareVersion
- softReset
- disconnect
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.