Class: I2CDevice::HDC1000
- Defined in:
- lib/templates/grove_pi/i2c/device/hdc1000.rb
Overview
www.ti.com/product/HDC1000 A Digital humidity/temperature sensor
Constant Summary
Constants inherited from I2CDevice
Instance Attribute Summary
Attributes inherited from I2CDevice
Instance Method Summary collapse
- #calc_humidity(d1, d2) ⇒ Object
- #calc_temperature(d1, d2) ⇒ Object
- #configuration ⇒ Object
- #get_data ⇒ Object
-
#initialize(args = {}) ⇒ HDC1000
constructor
A new instance of HDC1000.
Methods inherited from I2CDevice
Constructor Details
#initialize(args = {}) ⇒ HDC1000
Returns a new instance of HDC1000.
9 10 11 12 13 14 15 |
# File 'lib/templates/grove_pi/i2c/device/hdc1000.rb', line 9 def initialize(args = {}) args = { address: 0x40 }.merge(args) super args configuration end |
Instance Method Details
#calc_humidity(d1, d2) ⇒ Object
39 40 41 |
# File 'lib/templates/grove_pi/i2c/device/hdc1000.rb', line 39 def calc_humidity(d1, d2) (d1<<8 | d2).to_f / 2**16 * 100 end |
#calc_temperature(d1, d2) ⇒ Object
35 36 37 |
# File 'lib/templates/grove_pi/i2c/device/hdc1000.rb', line 35 def calc_temperature(d1, d2) ((d1<<8 | d2).to_f / 2**16 * 165) - 40 end |
#configuration ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/templates/grove_pi/i2c/device/hdc1000.rb', line 17 def configuration i2cset( 0x02, # Configuration register 0x10, # TRES 14bit 0x00 # HRES 14bit ) end |
#get_data ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/templates/grove_pi/i2c/device/hdc1000.rb', line 25 def get_data i2cset(0x00) sleep 6.35e-3 + 6.5e-3 raw = i2cget(nil, 4).unpack("C4") { temperature: calc_temperature(raw[0], raw[1]), humidity: calc_humidity(raw[2], raw[3]) } end |