1.0.15 • Published 2 years ago

@marnibrewster/scd4x-node v1.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@marnibrewster/scd4x-node

This is a version of RSmeral's scd4x-node library that is actually working on a scd4x on a raspberry pi B. Through a lot of trial and error, and looking at aphotix's raspi-node-sht31 library, I realized that when using i2c-bus, it is not possible to use the scd4x start_periodic_measurement functionality, regardless of which i2c-bus (promises, plain i2c + buffers, asyc, or sync) were used. Therefore, this library only utilizes the getStatus, readSensorData, and reset functionality, and leaves the i2c connection up to the i2c-bus library.

This is a node.js library for Sensirion SCD40 and SCD41, the CO2, temperature, and humidity sensors.

The library exposes some 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 @marnibrewster/scd4x-node
const SCD4x = require("@marnibrewster/scd4x-node");

const scd4x = new SCD4x();

scd4x
	.getStatus()
	.then(() => scd4x.readSensorData().then(console.log, console.log));

API Documentation

Class SCD4x

getStatus(): Promise<boolean>

aka "get_data_ready_status" in the Sensirion docs, see page 14

Indicates whether a measurement can be read from the sensor's buffer. Should be called before readSensorData. Throws an error if the least significant 11 bits of the response are 0.

readSensorData(): Promise<Measurement>

aka "read_measurement" in the Sensirion docs, see page 9

Read a measurement of CO2 concentration, temperature, and humidity.

reset(): void

same name in the Sensirion docs, see page 16

Performs a factory reset of the sensor.

Troubleshooting

  1. Make sure that you have node and npm installed on your pi: running node -- version and npm --version should output numbers. If they do not, you need to find out how to install node on your pi. This varies based on your pi version, but "Step 2" of this tutorial was most helpful for me on my very old pi B.. I found that the Unofficial Builds on Nodejs.org were the most successful in installing.
  2. Make sure that your sensor is wired properly
  3. Make sure that i2c is enabled on your raspberry pi.

    1. sudo apt-get install -y i2c-tools
    2. sudo i2cdetect -y 1
      1. this should output a weird looking 'picture', and there should be an "x" at the 62 location if your sensor is wired up properly. Try
    sudo i2cdetect -y 0

    if this doesn't work. If both return empty, your sensor isn't wired up properly. Google the pinout for your raspberry pi, shutdown your pi, rewire it, and reboot it. If that doesn't work, try different wires and or check your soldering.

  4. Run a simple python script to make sure that you can 'talk' to your sensor: (instructions from the link in #2, run these separately):

    sudo apt-get update
    sudo apt-get install python3-pip
    pip3 install adafruit-circuitpython-scd4x
    nano testSensor.py

    copy and paste the code from the adafruit tutorial here, then save your work (control + x, y, enter). Run the file with:

    python3 testSensor.py

    You should see the readout from your scd4x in your terminal. Once you have confirmed that the sensor is working properly, you can move onto troubleshooting this library.

  5. In your pi, create a directory in home/pi called "Projects":

    mkdir Projects

    and go into it:

    cd Projects

    Make a new directory called TestSensor:

    mkdir TestSensor

    and go into it:

    cd TestSensor

    Run

    npm init

    to initialize a node project where you can install this library. Run

    npm install @marnibrewster/scd4x-node

    to install this library and its dependencies. Create and open a file called test.js by running

    nano test.js
    node test.js

    You should see the output of your sensor in this shape:

    {
       co2: number,
       temperature: number,
       humidity: number
    }
1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago