Sensiron SHT 7x Temperature and humidity device library

Dependents:   temp xj-Nucleo-F303K8-SHT75-TEST

Committer:
nimbusgb
Date:
Wed Oct 27 15:51:27 2010 +0000
Revision:
1:20aa2d4a28bf
Child:
2:dd218144f9fe

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nimbusgb 1:20aa2d4a28bf 1 /* mbed Sensiron SHT7x temperature and humidity sensor library
nimbusgb 1:20aa2d4a28bf 2 *
nimbusgb 1:20aa2d4a28bf 3 * Sensiron data at http://www.sensirion.com/en/01_humidity_sensors/06_humidity_sensor_sht75.htm
nimbusgb 1:20aa2d4a28bf 4 *
nimbusgb 1:20aa2d4a28bf 5 * Copyright (c) Ian Molesworth October 2010
nimbusgb 1:20aa2d4a28bf 6 *
nimbusgb 1:20aa2d4a28bf 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
nimbusgb 1:20aa2d4a28bf 8 * of this software and associated documentation files (the "Software"), to use
nimbusgb 1:20aa2d4a28bf 9 * copy or modify the software for private or non-commercial purposes only.
nimbusgb 1:20aa2d4a28bf 10 *
nimbusgb 1:20aa2d4a28bf 11 * The above copyright notice and this permission notice shall be included in
nimbusgb 1:20aa2d4a28bf 12 * all copies or substantial portions of the Software.
nimbusgb 1:20aa2d4a28bf 13 *
nimbusgb 1:20aa2d4a28bf 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
nimbusgb 1:20aa2d4a28bf 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
nimbusgb 1:20aa2d4a28bf 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
nimbusgb 1:20aa2d4a28bf 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
nimbusgb 1:20aa2d4a28bf 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
nimbusgb 1:20aa2d4a28bf 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
nimbusgb 1:20aa2d4a28bf 20 * THE SOFTWARE.
nimbusgb 1:20aa2d4a28bf 21 */
nimbusgb 1:20aa2d4a28bf 22
nimbusgb 1:20aa2d4a28bf 23
nimbusgb 1:20aa2d4a28bf 24 #ifndef SHT75_H
nimbusgb 1:20aa2d4a28bf 25 #define SHT75_H
nimbusgb 1:20aa2d4a28bf 26
nimbusgb 1:20aa2d4a28bf 27 #include "mbed.h"
nimbusgb 1:20aa2d4a28bf 28
nimbusgb 1:20aa2d4a28bf 29 const float C1= -4.0; // for 12 Bit humi
nimbusgb 1:20aa2d4a28bf 30 const float C2= +0.0405; // for 12 Bit humi
nimbusgb 1:20aa2d4a28bf 31 const float C3= -0.0000028; // for 12 Bit hum
nimbusgb 1:20aa2d4a28bf 32 const float TL= -39.61; // 3v 14 bit
nimbusgb 1:20aa2d4a28bf 33 const float T1= +0.01; // for 14 Bit @ 5V
nimbusgb 1:20aa2d4a28bf 34 const float T2= +0.00008; // for 14 Bit @ 5V
nimbusgb 1:20aa2d4a28bf 35
nimbusgb 1:20aa2d4a28bf 36 /** SHT7x class
nimbusgb 1:20aa2d4a28bf 37 *
nimbusgb 1:20aa2d4a28bf 38 * Example:
nimbusgb 1:20aa2d4a28bf 39 * @code
nimbusgb 1:20aa2d4a28bf 40 * //initialise the device read temperature ticks, read humidity ticks and then
nimbusgb 1:20aa2d4a28bf 41 * calculate the liniarised humidity value.
nimbusgb 1:20aa2d4a28bf 42 * #include "mbed.h"
nimbusgb 1:20aa2d4a28bf 43 * #include "SHT7X.h"
nimbusgb 1:20aa2d4a28bf 44 00035 *
nimbusgb 1:20aa2d4a28bf 45 00036 * Servo myservo(p21);
nimbusgb 1:20aa2d4a28bf 46 00037 *
nimbusgb 1:20aa2d4a28bf 47 00038 * int main() {
nimbusgb 1:20aa2d4a28bf 48 00039 * while(1) {
nimbusgb 1:20aa2d4a28bf 49 00040 * for(int i=0; i<100; i++) {
nimbusgb 1:20aa2d4a28bf 50 00041 * myservo = i/100.0;
nimbusgb 1:20aa2d4a28bf 51 00042 * wait(0.01);
nimbusgb 1:20aa2d4a28bf 52 00043 * }
nimbusgb 1:20aa2d4a28bf 53 00044 * for(int i=100; i>0; i--) {
nimbusgb 1:20aa2d4a28bf 54 00045 * myservo = i/100.0;
nimbusgb 1:20aa2d4a28bf 55 00046 * wait(0.01);
nimbusgb 1:20aa2d4a28bf 56 00047 * }
nimbusgb 1:20aa2d4a28bf 57 00048 * }
nimbusgb 1:20aa2d4a28bf 58 00049 * }
nimbusgb 1:20aa2d4a28bf 59 00050 * @endcode
nimbusgb 1:20aa2d4a28bf 60 00051 */
nimbusgb 1:20aa2d4a28bf 61 class SHT75
nimbusgb 1:20aa2d4a28bf 62 {
nimbusgb 1:20aa2d4a28bf 63 public:
nimbusgb 1:20aa2d4a28bf 64 /** Create an SHT object connected to the specified Digital pins
nimbusgb 1:20aa2d4a28bf 65 *
nimbusgb 1:20aa2d4a28bf 66 * @param pclock digital pin to use as clock
nimbusgb 1:20aa2d4a28bf 67 * @param pdata digital pin to use as data bus ( bidirectional )
nimbusgb 1:20aa2d4a28bf 68 */
nimbusgb 1:20aa2d4a28bf 69 SHT75(PinName pclock, PinName pdata): _clock(pclock), _data(pdata) {};
nimbusgb 1:20aa2d4a28bf 70 /** read the temperature ticks value 14 bit resolution
nimbusgb 1:20aa2d4a28bf 71 *
nimbusgb 1:20aa2d4a28bf 72 * @param int *temp pointer to an integer to hold the tick value
nimbusgb 1:20aa2d4a28bf 73 * @returns boolean true if read acknowledges
nimbusgb 1:20aa2d4a28bf 74 */
nimbusgb 1:20aa2d4a28bf 75 bool readTempTicks(int* temp);
nimbusgb 1:20aa2d4a28bf 76 /** read the humidity ticks value 12 bit resolution
nimbusgb 1:20aa2d4a28bf 77 *
nimbusgb 1:20aa2d4a28bf 78 * @param int *temp pointer to an integer to hold the tick value
nimbusgb 1:20aa2d4a28bf 79 * @returns boolean true if read acknowledges
nimbusgb 1:20aa2d4a28bf 80 */
nimbusgb 1:20aa2d4a28bf 81 bool readHumidityTicks(int* temp);
nimbusgb 1:20aa2d4a28bf 82 /** start up reset
nimbusgb 1:20aa2d4a28bf 83 *
nimbusgb 1:20aa2d4a28bf 84 * call to resync or abort current operation.
nimbusgb 1:20aa2d4a28bf 85 * worth calling every now and then to make sure your system is not hung.
nimbusgb 1:20aa2d4a28bf 86 */
nimbusgb 1:20aa2d4a28bf 87 void reset(void);
nimbusgb 1:20aa2d4a28bf 88 void softReset(void);
nimbusgb 1:20aa2d4a28bf 89 int readStatus(void);
nimbusgb 1:20aa2d4a28bf 90
nimbusgb 1:20aa2d4a28bf 91 private:
nimbusgb 1:20aa2d4a28bf 92 DigitalInOut _data;
nimbusgb 1:20aa2d4a28bf 93 DigitalOut _clock;
nimbusgb 1:20aa2d4a28bf 94
nimbusgb 1:20aa2d4a28bf 95 void start(void);
nimbusgb 1:20aa2d4a28bf 96 int read(char);
nimbusgb 1:20aa2d4a28bf 97 bool write(char);
nimbusgb 1:20aa2d4a28bf 98 };
nimbusgb 1:20aa2d4a28bf 99
nimbusgb 1:20aa2d4a28bf 100 #endif