Honeywell HumidIcon Digital Humidty/Temperature Sensor.
Dependents: test_HIH6130 testSensor
HIH6130.h@3:c8313fc2bd93, 2017-05-11 (annotated)
- Committer:
- Rhyme
- Date:
- Thu May 11 08:25:30 2017 +0000
- Revision:
- 3:c8313fc2bd93
- Parent:
- 2:c3d3f02b7cfe
- Child:
- 4:b5bedc9b6d04
some document added
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:8d7f06935726 | 84 | |
Rhyme | 2:c3d3f02b7cfe | 85 | /** |
Rhyme | 2:c3d3f02b7cfe | 86 | * get humidity and temperature |
Rhyme | 2:c3d3f02b7cfe | 87 | * |
Rhyme | 3:c8313fc2bd93 | 88 | * @param float *humidity humidity in % |
Rhyme | 2:c3d3f02b7cfe | 89 | * @param float *temperature temperature in degree Celsius |
Rhyme | 3:c8313fc2bd93 | 90 | * @returns uint16_t status |
Rhyme | 3:c8313fc2bd93 | 91 | * |
Rhyme | 3:c8313fc2bd93 | 92 | * @note status bit |
Rhyme | 3:c8313fc2bd93 | 93 | * @note 00b: normal operation |
Rhyme | 3:c8313fc2bd93 | 94 | * @note 01b: stale data |
Rhyme | 3:c8313fc2bd93 | 95 | * @note 10b: device in Command Mode |
Rhyme | 3:c8313fc2bd93 | 96 | * @note 11b: diagnostic condition |
Rhyme | 2:c3d3f02b7cfe | 97 | */ |
Rhyme | 0:8d7f06935726 | 98 | uint16_t getValue(float *humidity, float *temperature) ; |
Rhyme | 0:8d7f06935726 | 99 | |
Rhyme | 0:8d7f06935726 | 100 | private: |
Rhyme | 0:8d7f06935726 | 101 | I2C m_i2c; |
Rhyme | 0:8d7f06935726 | 102 | int m_addr; |
Rhyme | 0:8d7f06935726 | 103 | void readRegs(int addr, uint8_t * data, int len); |
Rhyme | 0:8d7f06935726 | 104 | void writeRegs(uint8_t * data, int len); |
Rhyme | 0:8d7f06935726 | 105 | |
Rhyme | 0:8d7f06935726 | 106 | }; |
Rhyme | 0:8d7f06935726 | 107 | |
Rhyme | 0:8d7f06935726 | 108 | #endif |