a library that provides a connection to a SHT21 temperature and humidity sensor Author: Graeme Coapes - Newcastle University, graeme.coapes@ncl.ac.uk Date: 29/11/12
Dependents: test_ncleee WeatherStation Temp_hum PROJ ... more
Diff: SHT21_ncleee.h
- Revision:
- 0:91e3e396bc6e
- Child:
- 1:73fc5aef174e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SHT21_ncleee.h Thu Nov 29 10:36:10 2012 +0000 @@ -0,0 +1,104 @@ +/** + * SHT21 - Temperature and Humidity Sensor by Sensiron + * + * This is a driver to connect to the sensor using an mbed device through an I2C interface + * + * Author: Graeme Coapes - Newcastle University + * Email: graeme.coapes@ncl.ac.uk + * + * Date: 28/11/2012 + * + */ + +#include "mbed.h" + + +#ifndef SHT21_ncleee +#define SHT21_ncleee + + /* + * Constants used in communication + * + * Refer to datasheet for full explanation + */ + + //Sensor I2C address + #define SHT_I2C_ADDR 0x80 + + //Commands... + //Trigger Temp with hold master + #define SHT_TRIG_TEMP_HOLD 0xE3 + //Trigger RH with hold master + #define SHT_TRIG_RH_HOLD 0xE5 + //Trigger Temp with no hold master + #define SHT_TRIG_TEMP 0xF3 + //Trigger RH with no hold master + #define SHT_TRIG_RH 0xF5 + //Write to user register + #define SHT_WRITE_REG 0xE6 + //Read from user register + #define SHT_READ_REG 0xE7 + //Soft reset the sensor + #define SHT_SOFT_RESET 0xFE + + //User Register information + + //Data precision settings + //RH 12 T 14 - default + #define SHT_PREC_1214 0x00 + //RH 8 T 10 + #define SHT_PREC_0812 0x01 + //RH 10 T 13 + #define SHT_PREC_1013 0x80 + //RH 11 T 11 + #define SHT_PREC_1111 0x81 + + //Battery status + #define SHT_BATTERY_STAT 0x40 + //Enable on chip heater + #define SHT_HEATER 0x04 + //Disable OTP reload + #define SHT_DISABLE_OTP 0x02 + + + //Fail conditions on the I2C bus + #define SHT_FAIL 1 + #define SHT_SUCCESS 0 + + //Author fail conditions + //1, 2, 3 can be used because these are status bits + //in the received measurement value + #define SHT_GOOD 0xFFFC + #define SHT_TRIG_FAIL 1 + #define SHT_READ_FAIL 2 + + + class SHT21 + { + private: + I2C *_i2c; + int triggerTemp(); + int requestTemp(); + unsigned short temperature; + int triggerRH(); + int requestRH(); + unsigned short humidity; + int wr(int cmd); + + public: + + /** Constructor - create a connection to a SHT21 temperature and humidity sensor + * through an I2C interface + * + * @param *i2c a pointer to the i2c interface that is used for communication + */ + SHT21(I2C *i2c); + int readTemp(); + int readHumidity(); + int reset(); + int setPrecision(char precision); + + }; + + +#endif