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:
- 1:73fc5aef174e
- Parent:
- 0:91e3e396bc6e
- Child:
- 2:1411bb5e8c0a
--- a/SHT21_ncleee.h Thu Nov 29 10:36:10 2012 +0000 +++ b/SHT21_ncleee.h Thu Nov 29 10:48:06 2012 +0000 @@ -1,3 +1,21 @@ +/* Copyright (c) 2012 Graeme Coapes, Newcastle University, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + /** * SHT21 - Temperature and Humidity Sensor by Sensiron * @@ -72,7 +90,36 @@ #define SHT_TRIG_FAIL 1 #define SHT_READ_FAIL 2 - + /** SHT21 Connection class, utilizing a I2C interface + * + * Example: + * @code + * #include "mbed.h" + * #include "SHT21_ncleee.h" + * + * + * DigitalOut myled(LED1); + * Serial pc(USBTX, USBRX); + * I2C i2c(p28,p27); + * SHT21 sht(&i2c); + * + * int main() + * { + * + * pc.printf("Hello World...\n\tTesting temperature Sensor\n"); + * + * int temperature = sht.readTemp(); + * + * pc.printf("Temperature is: %d \n", temperature); + * + * pc.printf("Experiment complete...\n"); + * + } + + * @endcode + * + * + */ class SHT21 { private: @@ -93,9 +140,48 @@ * @param *i2c a pointer to the i2c interface that is used for communication */ SHT21(I2C *i2c); + + /** Read the temperature value from the sensor \n + * + * Involves triggering the measuring unit then + * waiting for 100ms for the measuring to complete + * before reading the temperature + * + * @param returns The temperature, a value of either 1,2 or 3 corresponds to an error + */ int readTemp(); + + /** Read the humidity value from the sensor \n + * + * Involves triggering the measuring unit then + * waiting for 100ms for the measuring to complete + * before reading the humidity + * + * @param returns The humidity, a value of either 1,2 or 3 corresponds to an error + */ int readHumidity(); + + /** + * Perform a soft-reset of the sensor unit. + */ int reset(); + + /** + * Set the precision of the measuring + * + * //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 + * + * @param precision - the precision, refer to above or datasheet. + * + */ int setPrecision(char precision); };