![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Internet of Greens. Mini automated greenhouse, with an internet of sensors.
Dependencies: HC_SR04_Ultrasonic_Library PixelArrayBuffer Servo TSL2561 mbed-rtos mbed
Fork of Final_project by
th02.h
00001 // ********************************************************************************** 00002 // Driver definition for HopeRF TH02 temperature and humidity sensor 00003 // ********************************************************************************** 00004 // Creative Commons Attrib Share-Alike License 00005 // You are free to use/extend this library but please abide with the CC-BY-SA license: 00006 // http://creativecommons.org/licenses/by-sa/4.0/ 00007 // 00008 // For any explanation see TH02 sensor information at 00009 // http://www.hoperf.com/sensor/app/TH02.htm 00010 // 00011 // Code based on following datasheet 00012 // http://www.hoperf.com/upload/sensor/TH02_V1.1.pdf 00013 // 00014 // Written by Charles-Henri Hallard (http://hallard.me) 00015 //ported to mbed env by Philippe LAURENT (IUT de NICE France) 00016 // 00017 // History : V1.00 2014-07-14 - First release 00018 // V1.10 2015-04-13 - changed to Wire library instead of I2C 00019 // 00020 // All text above must be included in any redistribution. 00021 // 00022 // ********************************************************************************** 00023 #ifndef TH02_H 00024 #define TH02_H 00025 00026 #include <mbed.h> // 00027 00028 // TH02 I2C Device address 00029 #define TH02_I2C_ADDR 0x40 00030 00031 // TH02 Registers addresses 00032 #define TH02_STATUS 0 00033 #define TH02_DATAh 1 00034 #define TH02_DATAl 2 00035 #define TH02_CONFIG 3 00036 #define TH02_ID 17 00037 00038 // TH02 custom error code return function 00039 #define TH02_I2C_ERR 0xFF 00040 00041 // Unititialized values (arbitrary) 00042 #define TH02_UNINITIALIZED_TEMP 55555 // int32_t internal value 00043 #define TH02_UNINITIALIZED_RH 1111 // int32_t internal value 00044 #define TH02_UNDEFINED_VALUE 12345 // int16_t returned value 00045 00046 // we decide error if conversion is >= 50ms 00047 #define TH02_CONVERSION_TIME_OUT 50 00048 00049 // Bit definition of TH02 registers values 00050 #define TH02_STATUS_RDY 0x01 00051 00052 #define TH02_CONFIG_START 0x01 00053 #define TH02_CONFIG_HEAT 0x02 00054 #define TH02_CONFIG_TEMP 0x10 00055 #define TH02_CONFIG_HUMI 0x00 00056 #define TH02_CONFIG_FAST 0x20 00057 00058 // THO2 Linearization Coefficients 00059 #define TH02_A0 -4.7844 00060 #define TH02_A1 0.4008 00061 #define TH02_A2 -0.00393 00062 00063 // TH02 Temperature compensation Linearization Coefficients 00064 #define TH02_Q0 0.1973 00065 #define TH02_Q1 0.00237 00066 00067 00068 00069 00070 00071 class TH02 { 00072 public: 00073 TH02(uint8_t address); 00074 uint8_t getId(uint8_t * pvalue); 00075 uint8_t getId(void); 00076 uint8_t getStatus(uint8_t * pvalue); 00077 bool isConverting(void); 00078 uint8_t waitEndConversion(void); 00079 uint8_t getConfig(uint8_t * pvalue); 00080 uint8_t setConfig(uint8_t config); 00081 uint8_t startTempConv(bool fastmode = false, bool heater = false); 00082 uint8_t startRHConv(bool fastmode = false, bool heater = false); 00083 int16_t roundInt(float value); 00084 int16_t getConversionValue(void); 00085 int16_t getConpensatedRH(bool round); 00086 int32_t getLastRawRH(void); 00087 int32_t getLastRawTemp(void); 00088 00089 /** 00090 * TH02 constructor 00091 * 00092 * @param sda I2C data pin 00093 * @param scl I2C clock pin 00094 * @param address I2C slave sensor address 00095 00096 */ 00097 TH02(PinName sda, PinName scl, uint8_t address); 00098 00099 /** 00100 * MFRC522 destructor 00101 */ 00102 ~TH02(); 00103 00104 00105 00106 private: 00107 I2C m_I2C; 00108 uint8_t writeCommand(uint8_t command, bool release=true); 00109 uint8_t writeRegister(uint8_t reg, uint8_t value); 00110 uint8_t readRegister(uint8_t reg, uint8_t * value); 00111 00112 int32_t _last_temp; // Last measured temperature (for linearization) 00113 int32_t _last_rh; // Last measured RH 00114 uint8_t _address; // I2C Module Address 00115 00116 00117 00118 }; 00119 00120 00121 00122 #endif
Generated on Mon Jul 18 2022 05:50:58 by
![doxygen](doxygen.png)