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