These are the methods to interface the TMP006 sensor with the mbed controller.
Dependents: mbed_blinky_Tmp006_No2 mbed_blinky_Tmp006_3rd completesensor TMP006IR_HelloWorld
TMP006.h@0:48c0564d877a, 2013-10-16 (annotated)
- Committer:
- sammacjunkie
- Date:
- Wed Oct 16 19:59:52 2013 +0000
- Revision:
- 0:48c0564d877a
comments added;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sammacjunkie | 0:48c0564d877a | 1 | /** TMP006 Temperature methods. |
sammacjunkie | 0:48c0564d877a | 2 | * Used for interfacing the TMP006 with the mbed. |
sammacjunkie | 0:48c0564d877a | 3 | * |
sammacjunkie | 0:48c0564d877a | 4 | * Example: |
sammacjunkie | 0:48c0564d877a | 5 | * @code |
sammacjunkie | 0:48c0564d877a | 6 | * #include "mbed.h" |
sammacjunkie | 0:48c0564d877a | 7 | * #include "TMP006.h" |
sammacjunkie | 0:48c0564d877a | 8 | |
sammacjunkie | 0:48c0564d877a | 9 | * #define Address 0x80 |
sammacjunkie | 0:48c0564d877a | 10 | * |
sammacjunkie | 0:48c0564d877a | 11 | * TMP006 sensor(p9, p10, Address); |
sammacjunkie | 0:48c0564d877a | 12 | * |
sammacjunkie | 0:48c0564d877a | 13 | * int main() |
sammacjunkie | 0:48c0564d877a | 14 | * { |
sammacjunkie | 0:48c0564d877a | 15 | * while(1) { |
sammacjunkie | 0:48c0564d877a | 16 | * printf("TTemperature: %f F \r \n", sensor.readObjTempF(Address)); |
sammacjunkie | 0:48c0564d877a | 17 | * wait(0.5); |
sammacjunkie | 0:48c0564d877a | 18 | * } |
sammacjunkie | 0:48c0564d877a | 19 | * } |
sammacjunkie | 0:48c0564d877a | 20 | * @endcode |
sammacjunkie | 0:48c0564d877a | 21 | */ |
sammacjunkie | 0:48c0564d877a | 22 | |
sammacjunkie | 0:48c0564d877a | 23 | |
sammacjunkie | 0:48c0564d877a | 24 | #ifndef TMP006_H |
sammacjunkie | 0:48c0564d877a | 25 | #define TMP006_H |
sammacjunkie | 0:48c0564d877a | 26 | |
sammacjunkie | 0:48c0564d877a | 27 | #include "mbed.h" |
sammacjunkie | 0:48c0564d877a | 28 | |
sammacjunkie | 0:48c0564d877a | 29 | // Constants for calculating object temperature |
sammacjunkie | 0:48c0564d877a | 30 | #define TMP006_B0 -0.0000294 |
sammacjunkie | 0:48c0564d877a | 31 | #define TMP006_B1 -0.00000057 |
sammacjunkie | 0:48c0564d877a | 32 | #define TMP006_B2 0.00000000463 |
sammacjunkie | 0:48c0564d877a | 33 | #define TMP006_C2 13.4 |
sammacjunkie | 0:48c0564d877a | 34 | #define TMP006_TREF 298.15 |
sammacjunkie | 0:48c0564d877a | 35 | #define TMP006_A2 -0.00001678 |
sammacjunkie | 0:48c0564d877a | 36 | #define TMP006_A1 0.00175 |
sammacjunkie | 0:48c0564d877a | 37 | #define TMP006_S0 6.4 // * 10^-14 |
sammacjunkie | 0:48c0564d877a | 38 | |
sammacjunkie | 0:48c0564d877a | 39 | // Configuration Settings |
sammacjunkie | 0:48c0564d877a | 40 | #define TMP006_CFG_RESET 0x8000 |
sammacjunkie | 0:48c0564d877a | 41 | #define TMP006_CFG_MODEON 0x7000 |
sammacjunkie | 0:48c0564d877a | 42 | #define TMP006_CFG_1SAMPLE 0x0000 |
sammacjunkie | 0:48c0564d877a | 43 | #define TMP006_CFG_2SAMPLE 0x0200 |
sammacjunkie | 0:48c0564d877a | 44 | #define TMP006_CFG_4SAMPLE 0x0400 |
sammacjunkie | 0:48c0564d877a | 45 | #define TMP006_CFG_8SAMPLE 0x0600 |
sammacjunkie | 0:48c0564d877a | 46 | #define TMP006_CFG_16SAMPLE 0x0800 |
sammacjunkie | 0:48c0564d877a | 47 | #define TMP006_CFG_DRDYEN 0x0100 |
sammacjunkie | 0:48c0564d877a | 48 | #define TMP006_CFG_DRDY 0x0080 |
sammacjunkie | 0:48c0564d877a | 49 | |
sammacjunkie | 0:48c0564d877a | 50 | // Registers to read thermopile voltage and sensor temperature |
sammacjunkie | 0:48c0564d877a | 51 | #define TMP006_VOBJ 0x00 |
sammacjunkie | 0:48c0564d877a | 52 | #define TMP006_TAMB 0x01 |
sammacjunkie | 0:48c0564d877a | 53 | #define TMP006_CONFIG 0x02 |
sammacjunkie | 0:48c0564d877a | 54 | |
sammacjunkie | 0:48c0564d877a | 55 | class TMP006 |
sammacjunkie | 0:48c0564d877a | 56 | { |
sammacjunkie | 0:48c0564d877a | 57 | public: |
sammacjunkie | 0:48c0564d877a | 58 | |
sammacjunkie | 0:48c0564d877a | 59 | // Constructor |
sammacjunkie | 0:48c0564d877a | 60 | TMP006(PinName sda, PinName scl, int addr); |
sammacjunkie | 0:48c0564d877a | 61 | |
sammacjunkie | 0:48c0564d877a | 62 | /** Configures sensor, use before reading from it */ |
sammacjunkie | 0:48c0564d877a | 63 | void config(uint8_t addr, uint16_t samples); |
sammacjunkie | 0:48c0564d877a | 64 | |
sammacjunkie | 0:48c0564d877a | 65 | /** Read raw sensor temperature */ |
sammacjunkie | 0:48c0564d877a | 66 | int16_t readRawDieTemperature(uint8_t addr); |
sammacjunkie | 0:48c0564d877a | 67 | |
sammacjunkie | 0:48c0564d877a | 68 | /** Read raw thermopile voltage */ |
sammacjunkie | 0:48c0564d877a | 69 | int16_t readRawVoltage(uint8_t addr); |
sammacjunkie | 0:48c0564d877a | 70 | |
sammacjunkie | 0:48c0564d877a | 71 | /** Calculate object temperature (C) based on raw sensor temp and thermopile voltage */ |
sammacjunkie | 0:48c0564d877a | 72 | double readObjTempC(uint8_t addr); |
sammacjunkie | 0:48c0564d877a | 73 | |
sammacjunkie | 0:48c0564d877a | 74 | /** Calculate object temperature (F) based on raw sensor temp and thermopile voltage */ |
sammacjunkie | 0:48c0564d877a | 75 | double readObjTempF(uint8_t addr); |
sammacjunkie | 0:48c0564d877a | 76 | |
sammacjunkie | 0:48c0564d877a | 77 | /** Caculate sensor temperature (C) based on raw reading */ |
sammacjunkie | 0:48c0564d877a | 78 | double readDieTempC(uint8_t addr); |
sammacjunkie | 0:48c0564d877a | 79 | |
sammacjunkie | 0:48c0564d877a | 80 | /** Caculate sensor temperature (F) based on raw reading */ |
sammacjunkie | 0:48c0564d877a | 81 | double readDieTempF(uint8_t addr); |
sammacjunkie | 0:48c0564d877a | 82 | |
sammacjunkie | 0:48c0564d877a | 83 | /*! |
sammacjunkie | 0:48c0564d877a | 84 | Destroys instance. |
sammacjunkie | 0:48c0564d877a | 85 | */ |
sammacjunkie | 0:48c0564d877a | 86 | ~TMP006(); |
sammacjunkie | 0:48c0564d877a | 87 | |
sammacjunkie | 0:48c0564d877a | 88 | |
sammacjunkie | 0:48c0564d877a | 89 | |
sammacjunkie | 0:48c0564d877a | 90 | private: |
sammacjunkie | 0:48c0564d877a | 91 | I2C m_i2c; |
sammacjunkie | 0:48c0564d877a | 92 | int m_addr; |
sammacjunkie | 0:48c0564d877a | 93 | |
sammacjunkie | 0:48c0564d877a | 94 | }; |
sammacjunkie | 0:48c0564d877a | 95 | |
sammacjunkie | 0:48c0564d877a | 96 | #endif |