Description: mbed library to use a SENSIRION SHT1x/SHT7x sensor humidity and temperature
SHT1x.h
Go to the documentation of this file.
00001 /* 00002 * mbed library to use a SENSIRION SHT1x/SHT7x sensor 00003 * Copyright (c) 2011 Hiroshi Suga 00004 * Released under the MIT License: http://mbed.org/license/mit 00005 */ 00006 00007 /** @file 00008 * @brief mbed library to use a SENSIRION SHT1x/SHT7x sensor 00009 * humidity/temperature sensor SHT11, SHT15, SHT71, SHT75 (SENSIRION) 00010 * interface: I2C digital 00011 */ 00012 00013 #ifndef SHT1x_H 00014 #define SHT1x_H 00015 00016 #include "mbed.h" 00017 00018 /** 00019 * @brief resolution setting 00020 */ 00021 enum SHT_acc { 00022 SHT_low = 0, ///< RH 8bit, temp 12bit 00023 SHT_high = 1, ///< RH 10bit, temp 14bit 00024 }; 00025 00026 enum SHT_vdd { 00027 SHT_3V3 = 0, 00028 SHT_5V = 1, 00029 }; 00030 00031 /** 00032 * @brief SHT1x class 00033 */ 00034 class SHT1x : public Base { 00035 public: 00036 /** 00037 * @brief Initializes interface (private I2C) 00038 * @param p_sda port of I2C SDA 00039 * @param p_scl port of I2C SCL 00040 * @param p_acc resolution setting 00041 * @param p_vdd power 00042 */ 00043 SHT1x(PinName p_sda, PinName p_scl, SHT_acc p_acc = SHT_high, SHT_vdd p_vdd = SHT_3V3); 00044 00045 /** 00046 * @brief Initializes interface (public I2C) 00047 * @param p_i2c instance of I2C class 00048 * @param p_acc resolution setting 00049 * @param p_vdd power 00050 */ 00051 SHT1x(I2C& p_i2c, SHT_acc p_acc = SHT_high, SHT_vdd p_vdd = SHT_3V3); 00052 00053 /** 00054 * @brief Get temperature 00055 * @return temperature (`C) 00056 */ 00057 float get_temperature(); 00058 00059 /** 00060 * @brief Get humidity 00061 * @return humidity (%) 00062 */ 00063 float get_humidity(); 00064 00065 /** 00066 * @brief Update results 00067 */ 00068 void update(); 00069 00070 protected: 00071 void init(SHT_acc p_acc, SHT_vdd p_vdd); 00072 unsigned short twi_readshort (int addr, int wait); 00073 void twi_writechar (int, int); 00074 00075 I2C i2c; 00076 float humidity, temperature; 00077 00078 private: 00079 float d1, d2, c1, c2, c3, t1, t2; 00080 enum SHT_acc accuracy; 00081 }; 00082 00083 #endif
