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 Ksenia Kondrashova

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.

/media/uploads/Ksenia/3-in-1-small.png

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:

/media/uploads/Ksenia/freshpaint-20-2016.09.16-10.37.03.png

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

Revision:
0:cb02bfe8cf44
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HYT.cpp	Wed Sep 14 15:22:42 2016 +0000
@@ -0,0 +1,42 @@
+#include "HYT.h"
+#include "mbed.h"
+
+HYT::HYT(PinName sda, PinName scl) : _i2c(sda, scl)
+{
+}
+
+/*************************************************************************************************************************/
+void HYT::MRCommand(void)
+{
+    _i2c.write(HYT_ADDR, 0, 0);
+}
+
+
+/*************************************************************************************************************************/
+int HYT::DFCommand(void)
+{
+    char    dataI2C[4];
+    int     stateBit;
+    int     humidityRaw;
+    int     temperatureRaw;
+
+    _i2c.read(HYT_ADDR, dataI2C, 4);
+
+    stateBit = (dataI2C[0] & 0x40) >> 6;
+    if (stateBit == 0) {
+        humidityRaw = ((dataI2C[0] & 0x3F) << 8) | dataI2C[1];
+        temperatureRaw = ((dataI2C[2] << 8) | dataI2C[3]) >> 2;
+        if (temperatureRaw < 0x3FFF && humidityRaw < 0x3FFF) {
+            temperature = ((float)(temperatureRaw) * 165.0f / 16383.0f) - 40.0f;
+            humidity = (float)humidityRaw * 100.0f / 16383.0f;
+        } else {
+            // sensor returns wrong data (1111...11)
+            return -1;
+        }
+    } else {
+        // no new value received from sensor
+        return 0;    
+    } 
+    
+    return 0;
+}
\ No newline at end of file