Class: IoT::HTU21D
- Inherits:
-
HumitureSensor
- Object
- Receptor
- DigitalReceptor
- DigitalSensor
- TemperatureSensor
- HumitureSensor
- IoT::HTU21D
- Defined in:
- lib/iot/htu21d.rb
Overview
HTU21D - relative humidity and temperature digital senspr
Constant Summary collapse
- I2C_ADDR =
inspired by github.com/leon-anavi/rpi-examples/HTU21D
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
-
#initialize(device_address = I2C_ADDR, bus_number = 1) ⇒ HTU21D
constructor
A new instance of HTU21D.
- #name ⇒ Object
-
#read_data ⇒ Object
Read values by ‘DhtSensor.read’ from ‘dht-sensor-ffi’.
Methods inherited from HumitureSensor
Methods inherited from TemperatureSensor
#celsius, #fahrenheit, #kelvin, #reaumur, #temperature, #to_s
Methods inherited from DigitalReceptor
Methods inherited from Receptor
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
#name ⇒ Object
34 35 36 |
# File 'lib/iot/htu21d.rb', line 34 def name @sensor_name end |
#read_data ⇒ Object
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 |