0.2.0 • Published 10 years ago

htu21d v0.2.0

Weekly downloads
1
License
BSD
Repository
github
Last release
10 years ago

htu21d

node interface for the HTU21D temperature and humidity sensor for Raspberry Pi

Install

$ npm install htu21d

Usage

var htu21d = require('htu21d');

var device = "/dev/i2c-1"
var address = 0x40;

var sensor = new htu21d.Htu21d(device, address);

var temp = sensor.temperature();

var humidity = sensor.humidity();

# turn on the internal heater
sensor.setHeater(true)

var check_temp = sensor.temperature();

var check_humidity = sensor.humidity();

# disable the internal heater

sensor.setHeater(false);

# set the measurement resolution, explained in the README

sensor.setMode(3);

var temp_lowres = sensor.temperature();

the htu21d object contains fields for sensor resolution, lowbattery status, and on-chip heater, as per the chip's capabilities, as well as devnode and chip address

> sensor

{ heater: false,
  lowbattery: false,
  resolution: { mode: 0, temperature: 14, humidity: 12 },
  devnode: '/dev/i2c-1',
  address: 64 }

The HTU21D has 4 modes for resolution, for which there is unfortunately no good way to express.

To change the resolution, consult the following table:

modeTempHumidity
014 bit12 bit
112 bit8 bit
213 bit10 bit
311 bit11 bit

Raspberry Pi Setup

$ sudo vi /etc/modules

Add these two lines

i2c-bcm2708 
i2c-dev
$ sudo vi /etc/modprobe.d/raspi-blacklist.conf

Comment out blacklist i2c-bcm2708

#blacklist i2c-bcm2708

Load kernel module

$ sudo modprobe i2c-bcm2708

Questions?

http://www.twitter.com/johnnysunshine