test MAX31850

Dependencies:   OneWireFB mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sht7X.h Source File

sht7X.h

00001 /* mbed Sensiron SHT7x temperature and humidity sensor library
00002 *
00003 * Sensiron data at http://www.sensirion.com/en/01_humidity_sensors/06_humidity_sensor_sht75.htm
00004 *
00005 * Copyright (c) Ian Molesworth October 2010
00006 *
00007 * Permission is hereby granted, free of charge, to any person obtaining a copy
00008 * of this software and associated documentation files (the "Software"), to use
00009 * copy or modify the software for private or non-commercial purposes only. 
00010 *
00011 * The above copyright notice and this permission notice shall be included in
00012 * all copies or substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 * THE SOFTWARE.
00021 */
00022 
00023 
00024 #ifndef SHT75_H
00025 #define SHT75_H
00026 
00027 #include "mbed.h"
00028 
00029 const float SHT_C1= -2.0468;              // for 12 Bit humi
00030 const float SHT_C2= +0.0367;           // for 12 Bit humi
00031 const float SHT_C3= 0;                  // for 12 Bit hum
00032 const float SHT_D1= -39.61;             // 3v3 14 bit //TL
00033 const float SHT_D2= 0.01;               //14BIT
00034 const float SHT_T1= +0.01;             // for 12 Bit 
00035 const float SHT_T2= +0.00008;          // for 12 Bit 
00036 
00037 /** SHT7X driver class
00038 *
00039 * Example:
00040 * @code
00041 * //initialise the device read temperature ticks, read humidity ticks and then
00042 * // calculate the liniarised humidity value.
00043 * #include "mbed.h"
00044 * #include "sht7X.h"
00045 * 
00046 * SHT75 sht(p12, p11); 
00047 * Serial pc(USBTX, USBRX); 
00048 * 
00049 * int main() 
00050 *     {
00051 *     float temperature;                    // temperature -40 to 120 deg C
00052 *     float humidity;                       // relative humidity 1% to 100%
00053 *     float humi_f,rh_lin,rh_true;           // working registers for Illustration purposes
00054 *     int t;                                // temporary store for the temp ticks
00055 *     int h;                                // temp store for the humidity ticks
00056 *
00057 *     pc.baud(115200);
00058 *
00059 *     while(1)
00060 *         {
00061 *         sht.readTempTicks(&t); 
00062 *         temperature = ((float)(t) * 0.01) - 39.61;
00063 *
00064 *         sht.readHumidityTicks(&h); 
00065 *         humi_f = (float)(h);
00066 *         rh_lin = C3 * humi_f * humi_f + C2 * humi_f + C1;
00067 *         rh_true=(((temperature/100)-25)*(T1+T2*humi_f)+rh_lin);
00068 *         if(rh_true>100)rh_true=100;                             //cut if the value is outside
00069 *         if(rh_true<1)rh_true=1;                                 //the physical possible range
00070 *         humidity = rh_true;                   
00071 *         pc.printf("Temp: %2.2f RH %2.2f\n\r",temperature, humidity);         
00072 *         }
00073 *     }
00074 * @endcode
00075 */
00076 
00077 class SHT75 
00078     {
00079     public:
00080      /**
00081       * @var temperature float to hold the temp
00082       */
00083         float temperature;
00084       /**
00085       * @var humidity float to hold the calculated humidity
00086       */
00087 
00088         float humidity;
00089     
00090      /** Create an SHT object connected to the specified Digital pins
00091       *
00092       * @param pclock digital pin to use as clock
00093       * @param pdata digital pin to use as data bus ( bidirectional ) 
00094       */
00095         SHT75(PinName pclock, PinName pdata): _clock(pclock), _data(pdata) {};
00096      /** read the temperature ticks value 14 bit resolution
00097       *
00098       * @param int *temp pointer to an integer to hold the tick value
00099       * @returns boolean true if read acknowledges
00100       */
00101         bool readTempTicks(int* temp);
00102      /** read the humidity ticks value 12 bit resolution
00103       *
00104       * @param int *temp pointer to an integer to hold the tick value
00105       * @returns boolean true if read acknowledges
00106       */
00107         bool readHumidityTicks(int* temp);
00108      /** start up reset
00109       *
00110       * call to resync or abort current operation.
00111       * worth calling every now and then to make sure your system is not hung.
00112       */
00113         void reset(void);
00114         void softReset(void);
00115         int  readStatus(void);
00116   
00117     private:  
00118         DigitalInOut _data;
00119         DigitalOut _clock;
00120         
00121         void start(void);
00122         int read(char);
00123         bool write(char);
00124     };
00125 
00126 #endif