Honeywell HumidIcon Digital Humidty/Temperature Sensor.

Dependents:   test_HIH6130 testSensor

Committer:
Rhyme
Date:
Tue May 16 02:34:57 2017 +0000
Revision:
5:939573b6796d
Parent:
4:b5bedc9b6d04
start_CM and start_NOM functions added

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 #ifndef HIH6130_H
Rhyme 0:8d7f06935726 20 #define HIH6130_H
Rhyme 0:8d7f06935726 21
Rhyme 0:8d7f06935726 22 #include "mbed.h"
Rhyme 0:8d7f06935726 23
Rhyme 0:8d7f06935726 24 /**
Rhyme 0:8d7f06935726 25 * Honeywell HumidIcon Digital Humidity/Temperature Sensors
Rhyme 0:8d7f06935726 26 *
Rhyme 0:8d7f06935726 27 * @code
Rhyme 1:1855077b0459 28 #include "mbed.h"
Rhyme 1:1855077b0459 29 #include "HIH6130.h"
Rhyme 1:1855077b0459 30 #define HIH6130_I2C_ADDRESS (0x27)
Rhyme 1:1855077b0459 31
Rhyme 1:1855077b0459 32 #if defined (TARGET_KL25Z)
Rhyme 1:1855077b0459 33 #define PIN_SCL PTE1
Rhyme 1:1855077b0459 34 #define PIN_SDA PTE0
Rhyme 1:1855077b0459 35 #elif defined (TARGET_KL46Z)
Rhyme 1:1855077b0459 36 #define PIN_SCL PTE1
Rhyme 1:1855077b0459 37 #define PIN_SDA PTE0
Rhyme 1:1855077b0459 38 #elif defined (TARGET_K64F)
Rhyme 1:1855077b0459 39 #define PIN_SCL PTE24
Rhyme 1:1855077b0459 40 #define PIN_SDA PTE25
Rhyme 1:1855077b0459 41 #elif defined (TARGET_K22F)
Rhyme 1:1855077b0459 42 #define PIN_SCL PTE1
Rhyme 1:1855077b0459 43 #define PIN_SDA PTE0
Rhyme 1:1855077b0459 44 #elif defined (TARGET_KL05Z)
Rhyme 1:1855077b0459 45 #define PIN_SCL PTB3
Rhyme 1:1855077b0459 46 #define PIN_SDA PTB4
Rhyme 1:1855077b0459 47 #elif defined (TARGET_NUCLEO_F411RE)
Rhyme 1:1855077b0459 48 #define PIN_SCL PB_8
Rhyme 1:1855077b0459 49 #define PIN_SDA PB_9
Rhyme 1:1855077b0459 50 #else
Rhyme 1:1855077b0459 51 #error TARGET NOT DEFINED
Rhyme 1:1855077b0459 52 #endif
Rhyme 1:1855077b0459 53
Rhyme 1:1855077b0459 54 int main() {
Rhyme 1:1855077b0459 55 uint16_t result = 0 ;
Rhyme 1:1855077b0459 56 float humidity = 0 ;
Rhyme 1:1855077b0459 57 float temperature = 0 ;
Rhyme 1:1855077b0459 58 HIH6130 hih(PIN_SDA, PIN_SCL, HIH6130_I2C_ADDRESS) ;
Rhyme 1:1855077b0459 59
Rhyme 1:1855077b0459 60 while(1) {
Rhyme 1:1855077b0459 61 result = hih.getValue(&humidity, &temperature) ;
Rhyme 1:1855077b0459 62 printf("Temp %.1f C Humidity %.1f %%\n", temperature, humidity) ;
Rhyme 1:1855077b0459 63 wait(1) ;
Rhyme 1:1855077b0459 64 }
Rhyme 1:1855077b0459 65 }
Rhyme 0:8d7f06935726 66 * @endcode
Rhyme 0:8d7f06935726 67 */
Rhyme 0:8d7f06935726 68 class HIH6130
Rhyme 0:8d7f06935726 69 {
Rhyme 0:8d7f06935726 70 public:
Rhyme 0:8d7f06935726 71 /**
Rhyme 0:8d7f06935726 72 * HIH6130 constructor
Rhyme 0:8d7f06935726 73 *
Rhyme 0:8d7f06935726 74 * @param sda SDA pin
Rhyme 0:8d7f06935726 75 * @param sdl SCL pin
Rhyme 0:8d7f06935726 76 * @param addr addr of the I2C peripheral
Rhyme 0:8d7f06935726 77 */
Rhyme 0:8d7f06935726 78 HIH6130(PinName sda, PinName scl, int addr);
Rhyme 0:8d7f06935726 79
Rhyme 0:8d7f06935726 80 /**
Rhyme 0:8d7f06935726 81 * HIH6130 destructor
Rhyme 0:8d7f06935726 82 */
Rhyme 0:8d7f06935726 83 ~HIH6130();
Rhyme 4:b5bedc9b6d04 84
Rhyme 4:b5bedc9b6d04 85 /**
Rhyme 4:b5bedc9b6d04 86 * Send MR (Measurement Request)
Rhyme 4:b5bedc9b6d04 87 *
Rhyme 4:b5bedc9b6d04 88 * @param none
Rhyme 4:b5bedc9b6d04 89 * @returns none
Rhyme 4:b5bedc9b6d04 90 * @note this wakes up the device and triggers a measurement cycle.
Rhyme 4:b5bedc9b6d04 91 */
Rhyme 4:b5bedc9b6d04 92 void measure(void) ;
Rhyme 0:8d7f06935726 93
Rhyme 2:c3d3f02b7cfe 94 /**
Rhyme 2:c3d3f02b7cfe 95 * get humidity and temperature
Rhyme 2:c3d3f02b7cfe 96 *
Rhyme 3:c8313fc2bd93 97 * @param float *humidity humidity in %
Rhyme 2:c3d3f02b7cfe 98 * @param float *temperature temperature in degree Celsius
Rhyme 3:c8313fc2bd93 99 * @returns uint16_t status
Rhyme 3:c8313fc2bd93 100 *
Rhyme 3:c8313fc2bd93 101 * @note status bit
Rhyme 3:c8313fc2bd93 102 * @note 00b: normal operation
Rhyme 3:c8313fc2bd93 103 * @note 01b: stale data
Rhyme 3:c8313fc2bd93 104 * @note 10b: device in Command Mode
Rhyme 3:c8313fc2bd93 105 * @note 11b: diagnostic condition
Rhyme 2:c3d3f02b7cfe 106 */
Rhyme 0:8d7f06935726 107 uint16_t getValue(float *humidity, float *temperature) ;
Rhyme 5:939573b6796d 108
Rhyme 5:939573b6796d 109 void start_CM(void) ;
Rhyme 5:939573b6796d 110 void start_NOM(void) ;
Rhyme 0:8d7f06935726 111
Rhyme 0:8d7f06935726 112 private:
Rhyme 0:8d7f06935726 113 I2C m_i2c;
Rhyme 0:8d7f06935726 114 int m_addr;
Rhyme 0:8d7f06935726 115 void readRegs(int addr, uint8_t * data, int len);
Rhyme 0:8d7f06935726 116 void writeRegs(uint8_t * data, int len);
Rhyme 0:8d7f06935726 117
Rhyme 0:8d7f06935726 118 };
Rhyme 0:8d7f06935726 119
Rhyme 0:8d7f06935726 120 #endif