Neverending Programming Mistakes

    scd4x-node
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    scd4x-node

    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.

    Usage

    yarn add scd4x-node
    const {SCD4x} = require('scd4x-node');
    
    (async () => {
      const scd4x = await SCD4x.connect();
      await scd4x.startPeriodicMeasurement();
    
      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();
    })();

    API Documentation

    Class 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:

    1. Operate the SCD4x in the operation mode later used in normal sensor operation (periodic measurement, low power periodic measurement or single shot) for > 3 minutes in an environment with homogenous and constant CO2 concentration.
    2. Call stopPeriodicMeasurement.
    3. Call 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.

    Install

    npm i scd4x-node

    DownloadsWeekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    34.6 kB

    Total Files

    13

    Last publish

    Collaborators

    • rsmeral