htu21d_for_weather_shield
Dependents: SPARKFUN_WEATHER_SHIELD
Fork of htu21d by
Diff: htu21d.h
- Revision:
- 0:2dab43acb3a4
- Child:
- 1:d3ed713f8354
diff -r 000000000000 -r 2dab43acb3a4 htu21d.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/htu21d.h Wed May 14 00:31:30 2014 +0000 @@ -0,0 +1,131 @@ +/** + */ + +#ifndef HTU21D_H +#define HTU21D_H + +#include "mbed.h" + +//Defines for HTU21D +#define HTU21Di2cWRITE 0x80 +#define HTU21Di2cREAD 0x81 + +#define HTU21DWRITEUSER 0xE6 +#define HTU21DREADUSER 0xE7 +#define HTU21DtempNOHOLD 0xF3 +#define HTU21DhumNOHOLD 0xF5 +#define HTU21DRESET 0xFE + +#define HTU21DHEATER 0x04 + + +/** + * Honeywell HTU21D digital humidity and temperature sensor. + */ +class htu21d { + +public: + /** + * Constructor. + * + * @param sda and scl, mbed I2C interface pins. + */ + htu21d(PinName sda, PinName scl); + /** + * De-constructor. + * + * @param --none--. + */ + ~htu21d(); + /** + * Get HTU21D Temperature. + * + * @param --none--. + * + * @return success / failure of HTU21D i2c access. 1 = ok, 0 = error. + */ + int softReset(); + /** + * Get HTU21D user register. + * + * @param --none--. + * + * @return success / failure of HTU21D i2c access. 1 = ok, 0 = error. + */ + uint8_t getUserReg(); + /** + * Turn ON the heater in the HTU21D. + * + * @param --none--. + * + * @return success / failure of HTU21D i2c access. 1 = ok, 0 = error. + */ + int heaterOn(); + /** + * Turn OFF the heater in the HTU21D. + * + * @param --none--. + * + * @return --none--. + */ + int heaterOff(); + /** + * Get heater on/off status in the HTU21D. + * + * @param --none--. + * + * @return 4 = on, 0 = 0ff. + */ + uint8_t getHeater(); + /** + * Do a reset on the HTU21D. + * + * @param --none--. + * + * @return float of Temperature in degrees C. 255.0 if error. + */ + float getTemp(); + /** + * Get HTU21D Humidity. + * + * @param --none--. + * + * @return float of Humidity in percentage. 255.0 if error. + */ + float getHum(); + /** + * Claculate the Dew Point. + * + * @param MUST run getTemp and getHum first!! + * + * @return float of Dew Point. + */ + float getDewPt(); + /** + * Claculate the Dew Point. 5x faster than getDewPt(). + * + * @param MUST run getTemp and getHum first!! + * + * @return float of Dew Point. + */ + float getDewPtFast(); + + + +private: + I2C _i2c; + /** + * I2C access for getting raw Temperature and Humidity data. + * + * @param 8 bit HTU21D register to get data from. Must use non-blocking regs. + * + * @return 16 bit raw i2c data, ANDed to 14 bits 0xFFFC. 0000 if error. + */ + uint16_t getData(uint8_t reg); + double theTempIs; + double theHumIs; + float getTrash(); + +}; + +#endif