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:10:49 2011 +0000
Revision:
3:834388db599d
Parent:
2:88af6eff8783
Child:
4:3ef9329a8ea7

        

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