Honeywell HumidIcon Digital Humidty/Temperature Sensor.

Dependents:   test_HIH6130 testSensor

Committer:
Rhyme
Date:
Sun Dec 13 08:34:46 2015 +0000
Revision:
0:8d7f06935726
Child:
4:b5bedc9b6d04
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:8d7f06935726 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Rhyme 0:8d7f06935726 2 *
Rhyme 0:8d7f06935726 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Rhyme 0:8d7f06935726 4 * and associated documentation files (the "Software"), to deal in the Software without
Rhyme 0:8d7f06935726 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Rhyme 0:8d7f06935726 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Rhyme 0:8d7f06935726 7 * Software is furnished to do so, subject to the following conditions:
Rhyme 0:8d7f06935726 8 *
Rhyme 0:8d7f06935726 9 * The above copyright notice and this permission notice shall be included in all copies or
Rhyme 0:8d7f06935726 10 * substantial portions of the Software.
Rhyme 0:8d7f06935726 11 *
Rhyme 0:8d7f06935726 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Rhyme 0:8d7f06935726 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Rhyme 0:8d7f06935726 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Rhyme 0:8d7f06935726 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Rhyme 0:8d7f06935726 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Rhyme 0:8d7f06935726 17 */
Rhyme 0:8d7f06935726 18
Rhyme 0:8d7f06935726 19 #include "HIH6130.h"
Rhyme 0:8d7f06935726 20
Rhyme 0:8d7f06935726 21 HIH6130::HIH6130(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr<<1) {
Rhyme 0:8d7f06935726 22 // activate the peripheral
Rhyme 0:8d7f06935726 23 }
Rhyme 0:8d7f06935726 24
Rhyme 0:8d7f06935726 25 HIH6130::~HIH6130() { }
Rhyme 0:8d7f06935726 26
Rhyme 0:8d7f06935726 27 uint16_t HIH6130::getValue(float *humidity, float *temperature)
Rhyme 0:8d7f06935726 28 {
Rhyme 0:8d7f06935726 29 uint16_t status = 0 ;
Rhyme 0:8d7f06935726 30 uint8_t data[4] ;
Rhyme 0:8d7f06935726 31 data[0] = 0x00 ;
Rhyme 0:8d7f06935726 32 readRegs(0, data, 4) ;
Rhyme 0:8d7f06935726 33
Rhyme 0:8d7f06935726 34 status = (data[0] >> 6) & 0x03 ;
Rhyme 0:8d7f06935726 35 *humidity = (float)((data[0] & 0x3F) * 256 + data[1]) * 100.0 / (float)0x3FFF ;
Rhyme 0:8d7f06935726 36 *temperature = (float)((data[2] * 64) + (data[3] >> 2)) * 165.0 / (float)0x3FFF - 40.0 ;
Rhyme 0:8d7f06935726 37 return( status ) ;
Rhyme 0:8d7f06935726 38 }
Rhyme 0:8d7f06935726 39
Rhyme 0:8d7f06935726 40 void HIH6130::readRegs(int addr, uint8_t * data, int len) {
Rhyme 0:8d7f06935726 41 char t[1] = {addr};
Rhyme 0:8d7f06935726 42 m_i2c.write(m_addr, t, 1, true);
Rhyme 0:8d7f06935726 43 m_i2c.read(m_addr, (char *)data, len);
Rhyme 0:8d7f06935726 44 }
Rhyme 0:8d7f06935726 45
Rhyme 0:8d7f06935726 46 void HIH6130::writeRegs(uint8_t * data, int len) {
Rhyme 0:8d7f06935726 47 m_i2c.write(m_addr, (char *)data, len);
Rhyme 0:8d7f06935726 48 }