test MAX31850

Dependencies:   OneWireFB mbed

Committer:
fblanc
Date:
Wed Sep 28 06:46:10 2016 +0000
Revision:
4:031e71e61e80
Parent:
0:55f2866e9c0c
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fblanc 0:55f2866e9c0c 1 /* mbed Sensiron SHT7x temperature and humidity sensor library
fblanc 0:55f2866e9c0c 2 *
fblanc 0:55f2866e9c0c 3 * Sensiron data at http://www.sensirion.com/en/01_humidity_sensors/06_humidity_sensor_sht75.htm
fblanc 0:55f2866e9c0c 4 *
fblanc 0:55f2866e9c0c 5 * Copyright (c) Ian Molesworth October 2010
fblanc 0:55f2866e9c0c 6 *
fblanc 0:55f2866e9c0c 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
fblanc 0:55f2866e9c0c 8 * of this software and associated documentation files (the "Software"), to use
fblanc 0:55f2866e9c0c 9 * copy or modify the software for private or non-commercial purposes only.
fblanc 0:55f2866e9c0c 10 *
fblanc 0:55f2866e9c0c 11 * The above copyright notice and this permission notice shall be included in
fblanc 0:55f2866e9c0c 12 * all copies or substantial portions of the Software.
fblanc 0:55f2866e9c0c 13 *
fblanc 0:55f2866e9c0c 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
fblanc 0:55f2866e9c0c 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
fblanc 0:55f2866e9c0c 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
fblanc 0:55f2866e9c0c 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
fblanc 0:55f2866e9c0c 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fblanc 0:55f2866e9c0c 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
fblanc 0:55f2866e9c0c 20 * THE SOFTWARE.
fblanc 0:55f2866e9c0c 21 */
fblanc 0:55f2866e9c0c 22
fblanc 0:55f2866e9c0c 23
fblanc 0:55f2866e9c0c 24 #ifndef SHT75_H
fblanc 0:55f2866e9c0c 25 #define SHT75_H
fblanc 0:55f2866e9c0c 26
fblanc 0:55f2866e9c0c 27 #include "mbed.h"
fblanc 0:55f2866e9c0c 28
fblanc 0:55f2866e9c0c 29 const float SHT_C1= -2.0468; // for 12 Bit humi
fblanc 0:55f2866e9c0c 30 const float SHT_C2= +0.0367; // for 12 Bit humi
fblanc 0:55f2866e9c0c 31 const float SHT_C3= 0; // for 12 Bit hum
fblanc 0:55f2866e9c0c 32 const float SHT_D1= -39.61; // 3v3 14 bit //TL
fblanc 0:55f2866e9c0c 33 const float SHT_D2= 0.01; //14BIT
fblanc 0:55f2866e9c0c 34 const float SHT_T1= +0.01; // for 12 Bit
fblanc 0:55f2866e9c0c 35 const float SHT_T2= +0.00008; // for 12 Bit
fblanc 0:55f2866e9c0c 36
fblanc 0:55f2866e9c0c 37 /** SHT7X driver class
fblanc 0:55f2866e9c0c 38 *
fblanc 0:55f2866e9c0c 39 * Example:
fblanc 0:55f2866e9c0c 40 * @code
fblanc 0:55f2866e9c0c 41 * //initialise the device read temperature ticks, read humidity ticks and then
fblanc 0:55f2866e9c0c 42 * // calculate the liniarised humidity value.
fblanc 0:55f2866e9c0c 43 * #include "mbed.h"
fblanc 0:55f2866e9c0c 44 * #include "sht7X.h"
fblanc 0:55f2866e9c0c 45 *
fblanc 0:55f2866e9c0c 46 * SHT75 sht(p12, p11);
fblanc 0:55f2866e9c0c 47 * Serial pc(USBTX, USBRX);
fblanc 0:55f2866e9c0c 48 *
fblanc 0:55f2866e9c0c 49 * int main()
fblanc 0:55f2866e9c0c 50 * {
fblanc 0:55f2866e9c0c 51 * float temperature; // temperature -40 to 120 deg C
fblanc 0:55f2866e9c0c 52 * float humidity; // relative humidity 1% to 100%
fblanc 0:55f2866e9c0c 53 * float humi_f,rh_lin,rh_true; // working registers for Illustration purposes
fblanc 0:55f2866e9c0c 54 * int t; // temporary store for the temp ticks
fblanc 0:55f2866e9c0c 55 * int h; // temp store for the humidity ticks
fblanc 0:55f2866e9c0c 56 *
fblanc 0:55f2866e9c0c 57 * pc.baud(115200);
fblanc 0:55f2866e9c0c 58 *
fblanc 0:55f2866e9c0c 59 * while(1)
fblanc 0:55f2866e9c0c 60 * {
fblanc 0:55f2866e9c0c 61 * sht.readTempTicks(&t);
fblanc 0:55f2866e9c0c 62 * temperature = ((float)(t) * 0.01) - 39.61;
fblanc 0:55f2866e9c0c 63 *
fblanc 0:55f2866e9c0c 64 * sht.readHumidityTicks(&h);
fblanc 0:55f2866e9c0c 65 * humi_f = (float)(h);
fblanc 0:55f2866e9c0c 66 * rh_lin = C3 * humi_f * humi_f + C2 * humi_f + C1;
fblanc 0:55f2866e9c0c 67 * rh_true=(((temperature/100)-25)*(T1+T2*humi_f)+rh_lin);
fblanc 0:55f2866e9c0c 68 * if(rh_true>100)rh_true=100; //cut if the value is outside
fblanc 0:55f2866e9c0c 69 * if(rh_true<1)rh_true=1; //the physical possible range
fblanc 0:55f2866e9c0c 70 * humidity = rh_true;
fblanc 0:55f2866e9c0c 71 * pc.printf("Temp: %2.2f RH %2.2f\n\r",temperature, humidity);
fblanc 0:55f2866e9c0c 72 * }
fblanc 0:55f2866e9c0c 73 * }
fblanc 0:55f2866e9c0c 74 * @endcode
fblanc 0:55f2866e9c0c 75 */
fblanc 0:55f2866e9c0c 76
fblanc 0:55f2866e9c0c 77 class SHT75
fblanc 0:55f2866e9c0c 78 {
fblanc 0:55f2866e9c0c 79 public:
fblanc 0:55f2866e9c0c 80 /**
fblanc 0:55f2866e9c0c 81 * @var temperature float to hold the temp
fblanc 0:55f2866e9c0c 82 */
fblanc 0:55f2866e9c0c 83 float temperature;
fblanc 0:55f2866e9c0c 84 /**
fblanc 0:55f2866e9c0c 85 * @var humidity float to hold the calculated humidity
fblanc 0:55f2866e9c0c 86 */
fblanc 0:55f2866e9c0c 87
fblanc 0:55f2866e9c0c 88 float humidity;
fblanc 0:55f2866e9c0c 89
fblanc 0:55f2866e9c0c 90 /** Create an SHT object connected to the specified Digital pins
fblanc 0:55f2866e9c0c 91 *
fblanc 0:55f2866e9c0c 92 * @param pclock digital pin to use as clock
fblanc 0:55f2866e9c0c 93 * @param pdata digital pin to use as data bus ( bidirectional )
fblanc 0:55f2866e9c0c 94 */
fblanc 0:55f2866e9c0c 95 SHT75(PinName pclock, PinName pdata): _clock(pclock), _data(pdata) {};
fblanc 0:55f2866e9c0c 96 /** read the temperature ticks value 14 bit resolution
fblanc 0:55f2866e9c0c 97 *
fblanc 0:55f2866e9c0c 98 * @param int *temp pointer to an integer to hold the tick value
fblanc 0:55f2866e9c0c 99 * @returns boolean true if read acknowledges
fblanc 0:55f2866e9c0c 100 */
fblanc 0:55f2866e9c0c 101 bool readTempTicks(int* temp);
fblanc 0:55f2866e9c0c 102 /** read the humidity ticks value 12 bit resolution
fblanc 0:55f2866e9c0c 103 *
fblanc 0:55f2866e9c0c 104 * @param int *temp pointer to an integer to hold the tick value
fblanc 0:55f2866e9c0c 105 * @returns boolean true if read acknowledges
fblanc 0:55f2866e9c0c 106 */
fblanc 0:55f2866e9c0c 107 bool readHumidityTicks(int* temp);
fblanc 0:55f2866e9c0c 108 /** start up reset
fblanc 0:55f2866e9c0c 109 *
fblanc 0:55f2866e9c0c 110 * call to resync or abort current operation.
fblanc 0:55f2866e9c0c 111 * worth calling every now and then to make sure your system is not hung.
fblanc 0:55f2866e9c0c 112 */
fblanc 0:55f2866e9c0c 113 void reset(void);
fblanc 0:55f2866e9c0c 114 void softReset(void);
fblanc 0:55f2866e9c0c 115 int readStatus(void);
fblanc 0:55f2866e9c0c 116
fblanc 0:55f2866e9c0c 117 private:
fblanc 0:55f2866e9c0c 118 DigitalInOut _data;
fblanc 0:55f2866e9c0c 119 DigitalOut _clock;
fblanc 0:55f2866e9c0c 120
fblanc 0:55f2866e9c0c 121 void start(void);
fblanc 0:55f2866e9c0c 122 int read(char);
fblanc 0:55f2866e9c0c 123 bool write(char);
fblanc 0:55f2866e9c0c 124 };
fblanc 0:55f2866e9c0c 125
fblanc 0:55f2866e9c0c 126 #endif