Class: IoT::HTU21D

Inherits:
HumitureSensor show all
Defined in:
lib/iot/htu21d.rb

Overview

HTU21D - relative humidity and temperature digital senspr

Constant Summary collapse

I2C_ADDR =
0x40
CMD_TRIG_TEMP_HM =
0xE3
CMD_TRIG_HUMID_HM =
0xE5
CMD_TRIG_TEMP_NHM =
0xF3
CMD_TRIG_HUMID_NHM =
0xF5
CMD_WRITE_USER_REG =
0xE6
CMD_READ_USER_REG =
0xE7
CMD_RESET =
0xFE

Instance Method Summary collapse

Methods inherited from HumitureSensor

#humidity, #to_s

Methods inherited from TemperatureSensor

#celsius, #fahrenheit, #kelvin, #reaumur, #temperature, #to_s

Methods inherited from DigitalReceptor

one_wire_file

Methods inherited from Receptor

#model_name, #read

Constructor Details

#initialize(device_address = I2C_ADDR, bus_number = 1) ⇒ HTU21D

Returns a new instance of HTU21D.



16
17
18
19
20
21
22
23
24
# File 'lib/iot/htu21d.rb', line 16

def initialize(device_address=I2C_ADDR, bus_number=1)
  @sensor_name = 'HTU21D'
  @device_address = device_address

  @buffer_size = 3
  @device = ::I2C.create("/dev/i2c-#{bus_number}")
  @device.write(I2C_ADDR, CMD_RESET)
  @temperature, @humidity = read_data
end

Instance Method Details

#nameObject



34
35
36
# File 'lib/iot/htu21d.rb', line 34

def name
  @sensor_name
end

#read_dataObject

Read values by ‘DhtSensor.read’ from ‘dht-sensor-ffi’



28
29
30
31
32
# File 'lib/iot/htu21d.rb', line 28

def read_data
  @temperature = t
  @humidity = h
  [@temperature, @humidity]
end