Lib for HYT temp & humidity sensor
Dependents: HYT_example Temp_&_RH_at_TFT-demo Temp_&_RH_at_TFT_with_touchscreen Temp_&_RH_at_TFT_with_touchscreen-ENG ... more
Fork of HYT by
This is a simple library for the HYT-271, HYT-221 and HYT-939 humidity and temperature sensors by IST-AG company. The difference between HYT sensors is only a package.
General information:
- High precision: +/-1.8%RH and 0.2°C
- Temperature range: -40°C to +125°C
- Low drift : less than 0,5% RH / year
- Power consumption: 22 µA during operation
- Fully calibrated and compensated humidity and temperature signal
- Digital I2C interface (14 bit values)
Product Page: http://www.ist-ag.com/eh/ist-ag/en/home.nsf/contentview/~humidity-modules
Remember to use pull-up resisrors:
You can also find Hello Word program sending data from sensor to PC via serial interface: https://developer.mbed.org/users/Ksenia/code/HYT_example/
Library doesn't contain command mode instructions. There are only functions for polling the HYT sensor with default i2c address
HYT.cpp@0:cb02bfe8cf44, 2016-09-14 (annotated)
- Committer:
- Ksenia
- Date:
- Wed Sep 14 15:22:42 2016 +0000
- Revision:
- 0:cb02bfe8cf44
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ksenia | 0:cb02bfe8cf44 | 1 | #include "HYT.h" |
Ksenia | 0:cb02bfe8cf44 | 2 | #include "mbed.h" |
Ksenia | 0:cb02bfe8cf44 | 3 | |
Ksenia | 0:cb02bfe8cf44 | 4 | HYT::HYT(PinName sda, PinName scl) : _i2c(sda, scl) |
Ksenia | 0:cb02bfe8cf44 | 5 | { |
Ksenia | 0:cb02bfe8cf44 | 6 | } |
Ksenia | 0:cb02bfe8cf44 | 7 | |
Ksenia | 0:cb02bfe8cf44 | 8 | /*************************************************************************************************************************/ |
Ksenia | 0:cb02bfe8cf44 | 9 | void HYT::MRCommand(void) |
Ksenia | 0:cb02bfe8cf44 | 10 | { |
Ksenia | 0:cb02bfe8cf44 | 11 | _i2c.write(HYT_ADDR, 0, 0); |
Ksenia | 0:cb02bfe8cf44 | 12 | } |
Ksenia | 0:cb02bfe8cf44 | 13 | |
Ksenia | 0:cb02bfe8cf44 | 14 | |
Ksenia | 0:cb02bfe8cf44 | 15 | /*************************************************************************************************************************/ |
Ksenia | 0:cb02bfe8cf44 | 16 | int HYT::DFCommand(void) |
Ksenia | 0:cb02bfe8cf44 | 17 | { |
Ksenia | 0:cb02bfe8cf44 | 18 | char dataI2C[4]; |
Ksenia | 0:cb02bfe8cf44 | 19 | int stateBit; |
Ksenia | 0:cb02bfe8cf44 | 20 | int humidityRaw; |
Ksenia | 0:cb02bfe8cf44 | 21 | int temperatureRaw; |
Ksenia | 0:cb02bfe8cf44 | 22 | |
Ksenia | 0:cb02bfe8cf44 | 23 | _i2c.read(HYT_ADDR, dataI2C, 4); |
Ksenia | 0:cb02bfe8cf44 | 24 | |
Ksenia | 0:cb02bfe8cf44 | 25 | stateBit = (dataI2C[0] & 0x40) >> 6; |
Ksenia | 0:cb02bfe8cf44 | 26 | if (stateBit == 0) { |
Ksenia | 0:cb02bfe8cf44 | 27 | humidityRaw = ((dataI2C[0] & 0x3F) << 8) | dataI2C[1]; |
Ksenia | 0:cb02bfe8cf44 | 28 | temperatureRaw = ((dataI2C[2] << 8) | dataI2C[3]) >> 2; |
Ksenia | 0:cb02bfe8cf44 | 29 | if (temperatureRaw < 0x3FFF && humidityRaw < 0x3FFF) { |
Ksenia | 0:cb02bfe8cf44 | 30 | temperature = ((float)(temperatureRaw) * 165.0f / 16383.0f) - 40.0f; |
Ksenia | 0:cb02bfe8cf44 | 31 | humidity = (float)humidityRaw * 100.0f / 16383.0f; |
Ksenia | 0:cb02bfe8cf44 | 32 | } else { |
Ksenia | 0:cb02bfe8cf44 | 33 | // sensor returns wrong data (1111...11) |
Ksenia | 0:cb02bfe8cf44 | 34 | return -1; |
Ksenia | 0:cb02bfe8cf44 | 35 | } |
Ksenia | 0:cb02bfe8cf44 | 36 | } else { |
Ksenia | 0:cb02bfe8cf44 | 37 | // no new value received from sensor |
Ksenia | 0:cb02bfe8cf44 | 38 | return 0; |
Ksenia | 0:cb02bfe8cf44 | 39 | } |
Ksenia | 0:cb02bfe8cf44 | 40 | |
Ksenia | 0:cb02bfe8cf44 | 41 | return 0; |
Ksenia | 0:cb02bfe8cf44 | 42 | } |