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 19:05:30 2011 +0000
Revision:
2:88af6eff8783
Parent:
1:257d9e026cc4
Child:
3:834388db599d

        

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 2:88af6eff8783 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 2:88af6eff8783 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 2:88af6eff8783 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 1:257d9e026cc4 23
tkreyche 1:257d9e026cc4 24
tkreyche 1:257d9e026cc4 25 #ifndef ADT7410_H
tkreyche 1:257d9e026cc4 26 #define ADT7410_H
tkreyche 1:257d9e026cc4 27
tkreyche 1:257d9e026cc4 28
tkreyche 1:257d9e026cc4 29
tkreyche 1:257d9e026cc4 30
tkreyche 2:88af6eff8783 31 /**
tkreyche 0:380ac1ac0101 32 *
tkreyche 0:380ac1ac0101 33 * Example:
tkreyche 0:380ac1ac0101 34 * @code
tkreyche 2:88af6eff8783 35 *
tkreyche 2:88af6eff8783 36 * #include "mbed.h"
tkreyche 2:88af6eff8783 37 * #include "ADT7410.h"
tkreyche 2:88af6eff8783 38 *
tkreyche 2:88af6eff8783 39 * ADT7410 tempSens1(p28, p27, 0x90, 100000);
tkreyche 2:88af6eff8783 40 *
tkreyche 2:88af6eff8783 41 * int main() {
tkreyche 2:88af6eff8783 42 *
tkreyche 2:88af6eff8783 43 * // reset sensor to default values
tkreyche 2:88af6eff8783 44 * tempSens1.reset();
tkreyche 2:88af6eff8783 45 *
tkreyche 2:88af6eff8783 46 * // read the config register, should be default
tkreyche 2:88af6eff8783 47 * printf("Config: 0x%x\n", tempSens1.getConfig());
tkreyche 2:88af6eff8783 48 *
tkreyche 2:88af6eff8783 49 * // reduce sample rate to save power
tkreyche 2:88af6eff8783 50 * tempSens1.setConfig(ONE_SPS_MODE);
tkreyche 2:88af6eff8783 51 *
tkreyche 2:88af6eff8783 52 * // check config register was set correctly
tkreyche 2:88af6eff8783 53 * printf("Config: 0x%x\n", tempSens1.getConfig());
tkreyche 2:88af6eff8783 54 *
tkreyche 2:88af6eff8783 55 * // get temperature every two seconds
tkreyche 2:88af6eff8783 56 * while (1) {
tkreyche 2:88af6eff8783 57 * printf("Deg C %f\n", tempSens1.getTemp());
tkreyche 2:88af6eff8783 58 * wait(2);
tkreyche 2:88af6eff8783 59 * }
tkreyche 2:88af6eff8783 60 * }
tkreyche 2:88af6eff8783 61 *
tkreyche 0:380ac1ac0101 62 * @endcode
tkreyche 0:380ac1ac0101 63 */
tkreyche 0:380ac1ac0101 64
tkreyche 1:257d9e026cc4 65
tkreyche 1:257d9e026cc4 66
tkreyche 0:380ac1ac0101 67
tkreyche 0:380ac1ac0101 68 #include "mbed.h"
tkreyche 0:380ac1ac0101 69
tkreyche 0:380ac1ac0101 70 // sensor register addresses
tkreyche 0:380ac1ac0101 71 // only a partial list, don't use them all
tkreyche 0:380ac1ac0101 72 #define TEMP_REG_ADDR 0x00
tkreyche 0:380ac1ac0101 73 #define CONFIG_REG_ADDR 0x03
tkreyche 0:380ac1ac0101 74 #define RESET 0x2F
tkreyche 0:380ac1ac0101 75
tkreyche 0:380ac1ac0101 76 // configuration register values
tkreyche 0:380ac1ac0101 77 // only a partial list, don't use them all
tkreyche 0:380ac1ac0101 78 #define ONE_SPS_MODE 0x40
tkreyche 0:380ac1ac0101 79
tkreyche 0:380ac1ac0101 80 //Library for the ADT7410 temperature sensor
tkreyche 0:380ac1ac0101 81
tkreyche 2:88af6eff8783 82 class ADT7410 {
tkreyche 0:380ac1ac0101 83
tkreyche 0:380ac1ac0101 84 public:
tkreyche 0:380ac1ac0101 85
tkreyche 2:88af6eff8783 86 // Creates an instance of the class.
tkreyche 2:88af6eff8783 87 // Connect module at I2C address addr using I2C port pins sda and scl
tkreyche 2:88af6eff8783 88 ADT7410(PinName sda, PinName scl, char addr, int hz);
tkreyche 2:88af6eff8783 89
tkreyche 2:88af6eff8783 90 //Destroys instance.
tkreyche 2:88af6eff8783 91 ~ADT7410();
tkreyche 2:88af6eff8783 92
tkreyche 2:88af6eff8783 93 //Reads the current temperature.
tkreyche 2:88af6eff8783 94 float getTemp();
tkreyche 2:88af6eff8783 95
tkreyche 2:88af6eff8783 96 //Set config register
tkreyche 2:88af6eff8783 97 void setConfig(char regVal);
tkreyche 2:88af6eff8783 98
tkreyche 2:88af6eff8783 99 //Get config register
tkreyche 2:88af6eff8783 100 char getConfig();
tkreyche 2:88af6eff8783 101
tkreyche 2:88af6eff8783 102 //Send reset
tkreyche 2:88af6eff8783 103 void reset();
tkreyche 2:88af6eff8783 104
tkreyche 0:380ac1ac0101 105 private:
tkreyche 2:88af6eff8783 106 I2C i2c;
tkreyche 2:88af6eff8783 107 char busAddr;
tkreyche 0:380ac1ac0101 108
tkreyche 0:380ac1ac0101 109 };
tkreyche 0:380ac1ac0101 110
tkreyche 0:380ac1ac0101 111 #endif