Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This library uses the i2c-bus nodeJS package to communicate with the chip over I2C.

Installation

npm install hdc302x

Usage

Basic Reading

const { HDC302x } = require('hdc302x');

(async () => {
    const sensor = new HDC302x();

    // Verify connection
    const mfgId = await sensor.readManufacturerId();
    console.log('Manufacturer ID:', mfgId.toString(16)); // Should be '3000'

    while (true) {
        const { temperature, humidity } = await sensor.read();
        console.log(`Temperature: ${temperature.toFixed(2)}°C, Humidity: ${humidity.toFixed(2)}%`);

        await new Promise((r) => setTimeout(r, 1000));
    }
})();

Auto Measurement Mode

const { HDC302x } = require('hdc302x');

(async () => {
    const sensor = new HDC302x();

    // Start auto measurement at 1 measurement per second
    await sensor.setAutoMode('1MPS_LP0');

    while (true) {
        const { temperature, humidity } = await sensor.readAuto();
        console.log(`Temperature: ${temperature.toFixed(2)}°C, Humidity: ${humidity.toFixed(2)}%`);

        await new Promise((r) => setTimeout(r, 1000));
    }

    // To stop auto mode:
    // await sensor.setAutoMode('EXIT_AUTO_MODE');
})();

Heater Control

const { HDC302x } = require('hdc302x');

(async () => {
    const sensor = new HDC302x();

    await sensor.setHeater('HALF_POWER');

    // Check heater status
    const heaterOn = await sensor.getHeater();
    console.log('Heater on:', heaterOn);

    // Disable heater
    await sensor.setHeater('OFF');
})();

Alert Thresholds

const { HDC302x } = require('hdc302x');

(async () => {
    const sensor = new HDC302x();

    // Set high alert at 30°C and 80% humidity
    await sensor.setHighAlert(30, 80);

    // Set low alert at 10°C and 20% humidity
    await sensor.setLowAlert(10, 20);

    // Check alert status
    const highAlert = await sensor.getHighAlert();
    const lowAlert = await sensor.getLowAlert();
    console.log('High alert:', highAlert, 'Low alert:', lowAlert);
})();

API Reference

Constructor Options

Option Default Description
i2cBusNumber 1 I2C bus number
address 0x44 I2C address (0x44, 0x45, 0x46, or 0x47)

Auto Modes

Mode Description
0.5MPS_LP0 - 0.5MPS_LP3 0.5 measurements per second
1MPS_LP0 - 1MPS_LP3 1 measurement per second
2MPS_LP0 - 2MPS_LP3 2 measurements per second
4MPS_LP0 - 4MPS_LP3 4 measurements per second
10MPS_LP0 - 10MPS_LP3 10 measurements per second
EXIT_AUTO_MODE Exit auto measurement mode

LP0-LP3 indicate low power modes, with LP3 being the lowest power consumption.

Heater Power Levels

Level Description
OFF Heater disabled
QUARTER_POWER 25% heater power
HALF_POWER 50% heater power
FULL_POWER 100% heater power

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages