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
ADT7410.h@8:e1aee50340ec, 2011-02-01 (annotated)
- Committer:
- tkreyche
- Date:
- Tue Feb 01 19:33:56 2011 +0000
- Revision:
- 8:e1aee50340ec
- Parent:
- 7:84351f613e8a
Who changed what in which revision?
User | Revision | Line number | New 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 | #ifndef ADT7410_H |
tkreyche | 1:257d9e026cc4 | 25 | #define ADT7410_H |
tkreyche | 1:257d9e026cc4 | 26 | |
tkreyche | 3:834388db599d | 27 | #include "mbed.h" |
tkreyche | 1:257d9e026cc4 | 28 | |
tkreyche | 3:834388db599d | 29 | // sensor register addresses |
tkreyche | 3:834388db599d | 30 | // only a partial list, don't use them all |
tkreyche | 3:834388db599d | 31 | #define TEMP_REG_ADDR 0x00 |
tkreyche | 3:834388db599d | 32 | #define CONFIG_REG_ADDR 0x03 |
tkreyche | 3:834388db599d | 33 | #define RESET 0x2F |
tkreyche | 3:834388db599d | 34 | |
tkreyche | 3:834388db599d | 35 | // configuration register values |
tkreyche | 3:834388db599d | 36 | // only a partial list, don't use them all |
tkreyche | 3:834388db599d | 37 | #define ONE_SPS_MODE 0x40 |
tkreyche | 3:834388db599d | 38 | |
tkreyche | 2:88af6eff8783 | 39 | /** |
tkreyche | 0:380ac1ac0101 | 40 | * |
tkreyche | 0:380ac1ac0101 | 41 | * Example: |
tkreyche | 0:380ac1ac0101 | 42 | * @code |
tkreyche | 2:88af6eff8783 | 43 | * |
tkreyche | 2:88af6eff8783 | 44 | * #include "mbed.h" |
tkreyche | 2:88af6eff8783 | 45 | * #include "ADT7410.h" |
tkreyche | 2:88af6eff8783 | 46 | * |
tkreyche | 2:88af6eff8783 | 47 | * ADT7410 tempSens1(p28, p27, 0x90, 100000); |
tkreyche | 2:88af6eff8783 | 48 | * |
tkreyche | 2:88af6eff8783 | 49 | * int main() { |
tkreyche | 2:88af6eff8783 | 50 | * |
tkreyche | 2:88af6eff8783 | 51 | * // reset sensor to default values |
tkreyche | 2:88af6eff8783 | 52 | * tempSens1.reset(); |
tkreyche | 2:88af6eff8783 | 53 | * |
tkreyche | 2:88af6eff8783 | 54 | * // read the config register, should be default |
tkreyche | 2:88af6eff8783 | 55 | * printf("Config: 0x%x\n", tempSens1.getConfig()); |
tkreyche | 2:88af6eff8783 | 56 | * |
tkreyche | 2:88af6eff8783 | 57 | * // reduce sample rate to save power |
tkreyche | 2:88af6eff8783 | 58 | * tempSens1.setConfig(ONE_SPS_MODE); |
tkreyche | 2:88af6eff8783 | 59 | * |
tkreyche | 2:88af6eff8783 | 60 | * // check config register was set correctly |
tkreyche | 2:88af6eff8783 | 61 | * printf("Config: 0x%x\n", tempSens1.getConfig()); |
tkreyche | 2:88af6eff8783 | 62 | * |
tkreyche | 2:88af6eff8783 | 63 | * // get temperature every two seconds |
tkreyche | 2:88af6eff8783 | 64 | * while (1) { |
tkreyche | 2:88af6eff8783 | 65 | * printf("Deg C %f\n", tempSens1.getTemp()); |
tkreyche | 2:88af6eff8783 | 66 | * wait(2); |
tkreyche | 2:88af6eff8783 | 67 | * } |
tkreyche | 2:88af6eff8783 | 68 | * } |
tkreyche | 2:88af6eff8783 | 69 | * |
tkreyche | 0:380ac1ac0101 | 70 | * @endcode |
tkreyche | 0:380ac1ac0101 | 71 | */ |
tkreyche | 0:380ac1ac0101 | 72 | |
tkreyche | 1:257d9e026cc4 | 73 | |
tkreyche | 1:257d9e026cc4 | 74 | |
tkreyche | 2:88af6eff8783 | 75 | class ADT7410 { |
tkreyche | 0:380ac1ac0101 | 76 | |
tkreyche | 0:380ac1ac0101 | 77 | public: |
tkreyche | 0:380ac1ac0101 | 78 | |
tkreyche | 5:112e732c8042 | 79 | /** Create a temperature sensor object |
tkreyche | 4:3ef9329a8ea7 | 80 | * @param sda I2C data |
tkreyche | 4:3ef9329a8ea7 | 81 | * @param scl I2C clock |
tkreyche | 4:3ef9329a8ea7 | 82 | * @param addr I2C bus address |
tkreyche | 4:3ef9329a8ea7 | 83 | * @param hz I2C bus speed |
tkreyche | 4:3ef9329a8ea7 | 84 | */ |
tkreyche | 2:88af6eff8783 | 85 | ADT7410(PinName sda, PinName scl, char addr, int hz); |
tkreyche | 2:88af6eff8783 | 86 | |
tkreyche | 5:112e732c8042 | 87 | /** Destroys object |
tkreyche | 5:112e732c8042 | 88 | */ |
tkreyche | 2:88af6eff8783 | 89 | ~ADT7410(); |
tkreyche | 2:88af6eff8783 | 90 | |
tkreyche | 5:112e732c8042 | 91 | /** Reads the current temperature |
tkreyche | 5:112e732c8042 | 92 | */ |
tkreyche | 2:88af6eff8783 | 93 | float getTemp(); |
tkreyche | 2:88af6eff8783 | 94 | |
tkreyche | 7:84351f613e8a | 95 | /** Change config register, currently only used to reduce power via 1SPS mode |
tkreyche | 7:84351f613e8a | 96 | * @param regVal new config register value, see datasheet for details |
tkreyche | 5:112e732c8042 | 97 | */ |
tkreyche | 2:88af6eff8783 | 98 | void setConfig(char regVal); |
tkreyche | 2:88af6eff8783 | 99 | |
tkreyche | 7:84351f613e8a | 100 | /** Read back config register |
tkreyche | 7:84351f613e8a | 101 | */ |
tkreyche | 2:88af6eff8783 | 102 | char getConfig(); |
tkreyche | 2:88af6eff8783 | 103 | |
tkreyche | 7:84351f613e8a | 104 | /** Reset sensor to default setting |
tkreyche | 7:84351f613e8a | 105 | */ |
tkreyche | 2:88af6eff8783 | 106 | void reset(); |
tkreyche | 2:88af6eff8783 | 107 | |
tkreyche | 0:380ac1ac0101 | 108 | private: |
tkreyche | 2:88af6eff8783 | 109 | I2C i2c; |
tkreyche | 2:88af6eff8783 | 110 | char busAddr; |
tkreyche | 0:380ac1ac0101 | 111 | |
tkreyche | 0:380ac1ac0101 | 112 | }; |
tkreyche | 0:380ac1ac0101 | 113 | |
tkreyche | 0:380ac1ac0101 | 114 | #endif |