htu21

package module
v0.0.0-...-e4f804b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 7 Imported by: 0

README

HTU21 (SHT21, SI7021) golang package

This package allows you to connect and read environmental data from HTU21 (SHT21, SI7021) sensor. I guess it could be qualified as a Periph.io driver, because it tries to comply with periph.io sensors interface like bmxx80 in terms of the ways to access I²C, function calls and data returned.

Example

You can find an example in cmd folder, it works on RPi 4 with HTU21 connected to 4-th I²C bus, sensor address is 0x40. List of I²C buses can be obtained with

i2cdetect -l

Once you know the bus number, connected devices can be enumerated with

i2cdetect -y 4

Some links you can find useful working with this sensor, RPi GPIO and I²C:

Why does this package exist?

This package is a heavily rewritten idahoakl/HTU21D-sensor library. Main differences are:

  • periph.io i2c package to access I²C instead of proprietary one, idahoakl used
  • periph.io physic package for environmental data (temperature and relative humidity)
  • one function Sense() instead of separate functions for each measurement
  • no proprietary logging package
  • no write/read user registry functions for now

I'd really like to get rid of proprietary CRC checking dependency as well.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dev

type Dev struct {
	// contains filtered or unexported fields
}

Dev is a handle to an initialized HTU21 device.

func NewI2C

func NewI2C(b i2c.Bus, addr uint16) (*Dev, error)

NewI2C returns an object that communicates over I²C to HTU21 environmental sensor.

HTU21 I²C device address is 0x40, according to the datasheet https://www.te.com/usa-en/models/4/00/028/790/CAT-HSC0004.html

func (*Dev) Reset

func (d *Dev) Reset() error

Performs soft reset of the device 0xFE - code for soft reset 15 milliseconds delay follows

func (*Dev) Sense

func (d *Dev) Sense(e *physic.Env) error

Sense requests a one time measurement as °C and % of relative humidity. 0xF3, delay 50 ms - temperature 0xF5, delay 16 ms - humidity

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL