Library for ADT7410 I2C temperature sensor. Use this instead of TMP102 when you need to measure temperatures lower than -40 degrees C. The device is guaranteed to work at -55 C but will actually read lower temps. See http://mbed.org/users/tkreyche/notebook/adt7140-i2c-temperature-sensor/ for more info.

Dependents:   BLE_ADT7410_TMP102_Sample BLE_HTM_HRM1017 BLENano_SimpleTemplate_temp_170802 BLENano_SimpleTemplate_temp_170813 ... more

Committer:
tkreyche
Date:
Tue Feb 01 18:57:41 2011 +0000
Revision:
0:380ac1ac0101
Child:
1:257d9e026cc4

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tkreyche 0:380ac1ac0101 1 /*
tkreyche 0:380ac1ac0101 2 Copyright (c) 2011 Tom Kreyche tkreyche@well.com
tkreyche 0:380ac1ac0101 3
tkreyche 0:380ac1ac0101 4 Permission is hereby granted, free of charge, to any person obtaining a copy
tkreyche 0:380ac1ac0101 5 of this software and associated documentation files (the "Software"), to deal
tkreyche 0:380ac1ac0101 6 in the Software without restriction, including without limitation the rights
tkreyche 0:380ac1ac0101 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
tkreyche 0:380ac1ac0101 8 copies of the Software, and to permit persons to whom the Software is
tkreyche 0:380ac1ac0101 9 furnished to do so, subject to the following conditions:
tkreyche 0:380ac1ac0101 10
tkreyche 0:380ac1ac0101 11 The above copyright notice and this permission notice shall be included in
tkreyche 0:380ac1ac0101 12 all copies or substantial portions of the Software.
tkreyche 0:380ac1ac0101 13
tkreyche 0:380ac1ac0101 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
tkreyche 0:380ac1ac0101 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
tkreyche 0:380ac1ac0101 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
tkreyche 0:380ac1ac0101 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
tkreyche 0:380ac1ac0101 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tkreyche 0:380ac1ac0101 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
tkreyche 0:380ac1ac0101 20 THE SOFTWARE.
tkreyche 0:380ac1ac0101 21 */
tkreyche 0:380ac1ac0101 22
tkreyche 0:380ac1ac0101 23 /** Servo control class, based on a PwmOut
tkreyche 0:380ac1ac0101 24 *
tkreyche 0:380ac1ac0101 25 * Example:
tkreyche 0:380ac1ac0101 26 * @code
tkreyche 0:380ac1ac0101 27
tkreyche 0:380ac1ac0101 28 #include "mbed.h"
tkreyche 0:380ac1ac0101 29 #include "ADT7410.h"
tkreyche 0:380ac1ac0101 30
tkreyche 0:380ac1ac0101 31 ADT7410 tempSens1(p28, p27, 0x90, 100000);
tkreyche 0:380ac1ac0101 32
tkreyche 0:380ac1ac0101 33 int main() {
tkreyche 0:380ac1ac0101 34
tkreyche 0:380ac1ac0101 35 // reset sensor to default values
tkreyche 0:380ac1ac0101 36 tempSens1.reset();
tkreyche 0:380ac1ac0101 37
tkreyche 0:380ac1ac0101 38 // read the config register, should be default
tkreyche 0:380ac1ac0101 39 printf("Config: 0x%x\n", tempSens1.getConfig());
tkreyche 0:380ac1ac0101 40
tkreyche 0:380ac1ac0101 41 // reduce sample rate to save power
tkreyche 0:380ac1ac0101 42 tempSens1.setConfig(ONE_SPS_MODE);
tkreyche 0:380ac1ac0101 43
tkreyche 0:380ac1ac0101 44 // check config register was set correctly
tkreyche 0:380ac1ac0101 45 printf("Config: 0x%x\n", tempSens1.getConfig());
tkreyche 0:380ac1ac0101 46
tkreyche 0:380ac1ac0101 47 // get temperature every two seconds
tkreyche 0:380ac1ac0101 48 while (1) {
tkreyche 0:380ac1ac0101 49
tkreyche 0:380ac1ac0101 50 printf("Deg C %f\n", tempSens1.getTemp());
tkreyche 0:380ac1ac0101 51 wait(2);
tkreyche 0:380ac1ac0101 52 }
tkreyche 0:380ac1ac0101 53 }
tkreyche 0:380ac1ac0101 54
tkreyche 0:380ac1ac0101 55 * @endcode
tkreyche 0:380ac1ac0101 56 */
tkreyche 0:380ac1ac0101 57
tkreyche 0:380ac1ac0101 58 #ifndef ADT7410_H
tkreyche 0:380ac1ac0101 59 #define ADT7410_H
tkreyche 0:380ac1ac0101 60
tkreyche 0:380ac1ac0101 61 #include "mbed.h"
tkreyche 0:380ac1ac0101 62
tkreyche 0:380ac1ac0101 63 // sensor register addresses
tkreyche 0:380ac1ac0101 64 // only a partial list, don't use them all
tkreyche 0:380ac1ac0101 65 #define TEMP_REG_ADDR 0x00
tkreyche 0:380ac1ac0101 66 #define CONFIG_REG_ADDR 0x03
tkreyche 0:380ac1ac0101 67 #define RESET 0x2F
tkreyche 0:380ac1ac0101 68
tkreyche 0:380ac1ac0101 69 // configuration register values
tkreyche 0:380ac1ac0101 70 // only a partial list, don't use them all
tkreyche 0:380ac1ac0101 71 #define ONE_SPS_MODE 0x40
tkreyche 0:380ac1ac0101 72
tkreyche 0:380ac1ac0101 73 //Library for the ADT7410 temperature sensor
tkreyche 0:380ac1ac0101 74
tkreyche 0:380ac1ac0101 75 class ADT7410
tkreyche 0:380ac1ac0101 76 {
tkreyche 0:380ac1ac0101 77
tkreyche 0:380ac1ac0101 78 public:
tkreyche 0:380ac1ac0101 79
tkreyche 0:380ac1ac0101 80 // Creates an instance of the class.
tkreyche 0:380ac1ac0101 81 // Connect module at I2C address addr using I2C port pins sda and scl
tkreyche 0:380ac1ac0101 82 ADT7410(PinName sda, PinName scl, char addr, int hz);
tkreyche 0:380ac1ac0101 83
tkreyche 0:380ac1ac0101 84 //Destroys instance.
tkreyche 0:380ac1ac0101 85 ~ADT7410();
tkreyche 0:380ac1ac0101 86
tkreyche 0:380ac1ac0101 87 //Reads the current temperature.
tkreyche 0:380ac1ac0101 88 float getTemp();
tkreyche 0:380ac1ac0101 89
tkreyche 0:380ac1ac0101 90 //Set config register
tkreyche 0:380ac1ac0101 91 void setConfig(char regVal);
tkreyche 0:380ac1ac0101 92
tkreyche 0:380ac1ac0101 93 //Get config register
tkreyche 0:380ac1ac0101 94 char getConfig();
tkreyche 0:380ac1ac0101 95
tkreyche 0:380ac1ac0101 96 //Send reset
tkreyche 0:380ac1ac0101 97 void reset();
tkreyche 0:380ac1ac0101 98
tkreyche 0:380ac1ac0101 99 private:
tkreyche 0:380ac1ac0101 100 I2C i2c;
tkreyche 0:380ac1ac0101 101 char busAddr;
tkreyche 0:380ac1ac0101 102
tkreyche 0:380ac1ac0101 103 };
tkreyche 0:380ac1ac0101 104
tkreyche 0:380ac1ac0101 105 #endif