Node.js library for Sensirion SCD40 and SCD41, the CO2, temperature, and humidity sensors.
The library exposes all of the commands supported by the SCD40 and SCD41, as documented in the official Datasheet.
Uses i2c-bus for connection to the sensor.
yarn add scd4x-node
const {SCD4x} = require('scd4x-node');
(async () => {
const scd4x = await SCD4x.connect();
try {
await scd4x.startPeriodicMeasurement();
// data is available 5s after starting periodic measurement
await new Promise(resolve => setTimeout(resolve, 5000));
} catch(e) {
console.log('Periodic measurement already turned on')
}
const measurement = await scd4x.readMeasurement();
console.log(`CO2 Concentration: ${measurement.co2Concentration} ppm`);
console.log(`Temperature: ${measurement.temperature} °C`);
console.log(`Humidity: ${measurement.relativeHumidity} %`);
await scd4x.disconnect();
})();
SCD4x
public static connect(busNumber: number = DEFAULT_I2C_BUS_NUMBER): Promise<SCD4x>
Connects to the SCD4x on the given I2C bus. Default bus number is 1.
startPeriodicMeasurement(): Promise<void>
Start periodic measurement, signal update interval is 5 seconds.
readMeasurement(): Promise<Measurement>
Read a measurement of CO2 concentration, temperature, and humidity.
stopPeriodicMeasurement(): Promise<void>
Stops continuous measurement.
setTemperatureOffset(offset: number): Promise<void>
Set temperature offset to improve accuracy of temperature and relative humidity measurements.
To save the setting permanently, call also persistSettings
.
getTemperatureOffset(): Promise<number>
Returns the temperature offset.
setSensorAltitude(altitude: number): Promise<void>
Reading and writing of the sensor altitude must be done while the SCD4x is in idle mode. Typically, the sensor altitude is set once after device installation.
getSensorAltitude(): Promise<number>
Returns the altitude compensation value in meters.
setAmbientPressure(pressure: number): Promise<void>
Can be sent during periodic measurements to enable continuous pressure compensation. Overrides any pressure compensation based on sensor altitude.
performForcedRecalibration(co2ppm: number): Promise<number>
To successfully conduct an accurate forced recalibration, the following steps need to be carried out:
stopPeriodicMeasurement
.performForcedRecalibration
and optionally read out the FRC correction (i.e. the magnitude of
the correction).setAutomaticSelfCalibrationEnabled(enable: boolean): Promise<void>
Activates or deactivates automatic self-calibration.
isAutomaticSelfCalibrationEnabled(): Promise<boolean>
Indicates whether automatic self-calibration is active.
startLowPowerPeriodicMeasurement(): Promise<void>
Start low power periodic measurement. Signal update interval is approximately 30 seconds.
isDataReady(): Promise<boolean>
Indicates whether a measurement can be read from the sensor's buffer.
persistSettings(): Promise<void>
Stores current configuration in the EEPROM of the SCD4x, making it persistent across power-cycling.
getSerialNumber(): Promise<number>
Returns the unique 48-bit serial number identifying the chip and verifying the presence of the sensor.
passesSelfTest(): Promise<boolean>
Performs a self test to check sensor functionality.
performFactoryReset(): Promise<void>
Resets all configuration settings stored in the EEPROM and erases the FRC and ASC algorithm history.
reinit(): Promise<void>
Reinitializes the sensor by reloading user settings from EEPROM.
measureSingleShot(): Promise<void>
Perform an on-demand measurement of CO2 concentration, relative humidity and temperature.
measureSingleShotRhtOnly(): Promise<void>
Perform an on-demand measurement of relative humidity and temperature only. CO2 output is returned as 0 ppm.
disconnect(): Promise<void>
Close the I2C bus.