HDC 1000 v0.1.0 Hdc1000.I2C View Source

I2C interface to HDC1000 sensor

This is a library for the HDC1000 Humidity & Temp Sensor

Designed specifically to work with the HDC100X sensors from Adafruit ----> https://www.adafruit.com/products/2635 These sensors use I2C to communicate, 2 pins are required to interface.

Please note: TI has indicated that there's a 'settling' effect for the humidity and that you will need to re-hydrate the sensor once you receive it. To rehydrate it, place it in a location with 85% humidity for 24 hours or 60% humidity for 10 days.

You will see really low sensor readings that do not properly calculate to actual RH when you need to re-hydrate. For my testing I used a 62rh 2 way humidity control packet in a sealed glass jar and let it rehydrate for 10 days. ----> https://amzn.to/2RAES5R

Link to this section Summary

Functions

Dries the sensor by running 1000 reads from it to heat it up.

Initializes the sensor and ensures it is open for communication.

Reads from the sensor and returns the relative humidity as a float

Reads from the sensor and returns the temperature in celcius as a float

Reads from the sensor and returns the temperature and relative humidity as a float in a tuple

Link to this section Types

Link to this section Functions

Link to this function

dry_sensor(sensor)

View Source
dry_sensor(sensor()) :: {:ok, float()} | {:error, String.t()}

Dries the sensor by running 1000 reads from it to heat it up.

Examples

iex> bus_name = Circuits.I2C.bus_names() |> hd()
"i2c-1"
iex> {:ok, sensor} = Hdc1000.I2C.init(bus_name)
{:ok, {#Reference<0.3684559318.805699597.133010>, 64}}
iex> Hdc1000.I2C.dry_sensor(sensor)
{:ok, 26.14501953125}
Link to this function

init(bus_name, address \\ 64)

View Source
init(bus_name(), address()) :: {:ok, {reference(), address()}}

Initializes the sensor and ensures it is open for communication.

Takes a bus name for I2C bus and an address for the sensor on the bus. If an address is not provided the default address of 0x40 will be used and returned to the caller.

If you are unsure about the devices bus_name run iex> Circuits.I2C.bus_names()

Returns ok tuple containing a tuple of the reference and the address of the sensor on I2C.

Examples

iex> bus_name = Circuits.I2C.bus_names() |> hd()
"i2c-1"
iex> {:ok, sensor} = Hdc1000.I2C.init(bus_name, 0x40)
{:ok, {#Reference<0.3684559318.805699597.133010>, 64}}

iex> {:ok, sensor} = Hdc1000.I2C.init(bus_name)
{:ok, {#Reference<0.3684559318.805699597.133010>, 64}}
Link to this function

read_rh(sensor)

View Source
read_rh(sensor()) :: {:ok, float()} | {:error, String.t()}

Reads from the sensor and returns the relative humidity as a float

Examples

iex> bus_name = Circuits.I2C.bus_names() |> hd()
"i2c-1"
iex> {:ok, sensor} = hdc1000.i2c.init(bus_name)
{:ok, {#Reference<0.3684559318.805699597.133010>, 64}}
iex> {:ok, rh} = Hdc1000.I2C.read_rh(sensor)
{:ok, 26.751708984375}

iex> # error case
iex> {:ok, rh} = Hdc1000.I2C.read_rh(sensor)
{:error, "Data for calculation is not an Integer: "}
Link to this function

read_temp(sensor)

View Source
read_temp(sensor()) :: {:ok, float()} | {:error, String.t()}

Reads from the sensor and returns the temperature in celcius as a float

Examples

iex> bus_name = Circuits.I2C.bus_names() |> hd()
"i2c-1"
iex> {:ok, sensor} = hdc1000.i2c.init(bus_name)
{:ok, {#Reference<0.3684559318.805699597.133010>, 64}}
iex> {:ok, temp} = Hdc1000.I2C.read_temp(sensor)
{:ok, 26.14501953125}

iex> # error case
iex> {:ok, temp} = Hdc1000.I2C.read_temp(sensor)
{:error, "Data for calculation is not an Integer: "}
Link to this function

read_temp_and_rh(sensor)

View Source
read_temp_and_rh(sensor()) :: {:ok, {float(), float()}} | {:error, String.t()}

Reads from the sensor and returns the temperature and relative humidity as a float in a tuple

Examples

iex> bus_name = Circuits.I2C.bus_names() |> hd()
"i2c-1"
iex> {:ok, sensor} = hdc1000.i2c.init(bus_name)
{:ok, {#Reference<0.3684559318.805699597.133010>, 64}}
iex> {:ok, {temp, rh}} = Hdc1000.I2C.read_temp_and_rh(sensor)
{:ok, {26.14501953125, 26.751708984375}}

iex> # error case
iex> {:ok, {temp, rh}} = Hdc1000.I2C.read_temp_and_rh(sensor)
{:error, "Data for calculation is not an Integer: "}