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

Files at this revision

API Documentation at this revision

Comitter:
Ksenia
Date:
Wed Sep 14 15:22:42 2016 +0000
Commit message:
Initial commit

Changed in this revision

HYT.cpp Show annotated file Show diff for this revision Revisions of this file
HYT.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r cb02bfe8cf44 HYT.cpp
--- /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
diff -r 000000000000 -r cb02bfe8cf44 HYT.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HYT.h	Wed Sep 14 15:22:42 2016 +0000
@@ -0,0 +1,85 @@
+#ifndef MBED_HYT_H
+#define MBED_HYT_H
+
+#include "mbed.h"
+
+/**
+ * IST HYT Humidity and Temperature Sensor
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "HYT.h"
+ * 
+ * Serial              pc(USBTX, USBRX);
+ * Ticker              timeKeeping;
+ * HYT                 SENSOR (I2C_SDA, I2C_SCL);
+ * 
+ * // HYT sensor polling cycle
+ * void dataUpdate(void)
+ * {
+ *     SENSOR.MRCommand();
+ *     wait_ms(100);
+ *     SENSOR.DFCommand();
+ * }
+ * 
+ * void secondsCallback(void) {
+ *     pc.printf("Humidity level: %.1f\r\n%", SENSOR.humidity);
+ *     pc.printf("Temperature level: %.1f\r\n%", SENSOR.temperature);
+ *     pc.printf("-------------------------------\r\n%", SENSOR.temperature);
+ * }
+ * 
+ * int main()
+ * {
+ *     timeKeeping.attach(&secondsCallback, 1.0f);
+ *     while(1) {
+ *          dataUpdate();
+ *     }
+ * }
+ * @endcode
+ */
+
+
+#define HYT_ADDR 0x50 // 01010000
+
+class HYT
+{
+    
+public:
+    /**
+     * HYT constructor.
+     *
+     * @param   sda mbed pin to use for SDA line of I2C interface.
+     * @param   scl mbed pin to use for SCL line of I2C interface.
+     * 
+     * Remember about pull-up resistors on sda and scl. Recommended value is 2.4 kΩ
+     */
+    HYT(PinName sda, PinName scl);
+
+    /**
+     * @brief   The totals (temperature in Celsius, relative humidity in percentages)
+     */
+    float humidity;
+    float temperature;
+    
+    /**
+     * @brief   Send "Measuring Request" command
+     * @details Initiates a measuring cycle of HYT sensor
+     * @details More information: http://www.ist-ag.com/eh/ist-ag/resource.nsf/imgref/Download_AHHYTM_E2.2.5.pdf/$FILE/AHHYTM_E2.2.5.pdf
+     */     
+    void MRCommand(void);
+    
+    /**
+     * @brief   Send "Data Fetch" command & processing the data
+     * @details Fetch the last measured value of humidity and temperature from sensor
+     * @details Calculate values of temperature in Celsius, relative humidity in percentages
+     * @details More information: http://www.ist-ag.com/eh/ist-ag/resource.nsf/imgref/Download_AHHYTM_E2.2.5.pdf/$FILE/AHHYTM_E2.2.5.pdf
+     * @returns 0 if no errors, -1 if no new value received from sensor.
+     */    
+     int DFCommand(void);
+     
+private:
+
+    I2C _i2c;
+};
+
+#endif
\ No newline at end of file