Drivber for Ti's TMP007 Infrared Thermopile Sensor with Integrated Math Engine
include/TMP007.h@1:93710a3abf0a, 2016-06-05 (annotated)
- Committer:
- messi1
- Date:
- Sun Jun 05 19:53:43 2016 +0000
- Revision:
- 1:93710a3abf0a
- Parent:
- 0:a1ed9ce625d4
Add TMP007_Defs.h file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
messi1 | 0:a1ed9ce625d4 | 1 | /** TMP007 Temperature methods. |
messi1 | 0:a1ed9ce625d4 | 2 | * Used for interfacing the TMP007 with the mbed. |
messi1 | 0:a1ed9ce625d4 | 3 | * |
messi1 | 0:a1ed9ce625d4 | 4 | * Example: |
messi1 | 0:a1ed9ce625d4 | 5 | * @code |
messi1 | 0:a1ed9ce625d4 | 6 | * #include "mbed.h" |
messi1 | 0:a1ed9ce625d4 | 7 | * #include "TMP007.h" |
messi1 | 0:a1ed9ce625d4 | 8 | |
messi1 | 0:a1ed9ce625d4 | 9 | * #define Address 0x40 // depending on pin ADR0 and ADR1 it can be either 0x40, 0x41, 0x44 or 0x45 |
messi1 | 0:a1ed9ce625d4 | 10 | * |
messi1 | 0:a1ed9ce625d4 | 11 | * TMP007 sensor(p9, p10, Address); |
messi1 | 0:a1ed9ce625d4 | 12 | * |
messi1 | 0:a1ed9ce625d4 | 13 | * int main() |
messi1 | 0:a1ed9ce625d4 | 14 | * { |
messi1 | 0:a1ed9ce625d4 | 15 | * while(1) { |
messi1 | 0:a1ed9ce625d4 | 16 | * printf("TTemperature: %f F \r \n", sensor.readObjTempF(Address)); |
messi1 | 0:a1ed9ce625d4 | 17 | * wait(0.5); |
messi1 | 0:a1ed9ce625d4 | 18 | * } |
messi1 | 0:a1ed9ce625d4 | 19 | * } |
messi1 | 0:a1ed9ce625d4 | 20 | * @endcode |
messi1 | 0:a1ed9ce625d4 | 21 | */ |
messi1 | 0:a1ed9ce625d4 | 22 | #ifndef TMP007_H |
messi1 | 0:a1ed9ce625d4 | 23 | #define TMP007_H |
messi1 | 0:a1ed9ce625d4 | 24 | |
messi1 | 0:a1ed9ce625d4 | 25 | #include <I2C.h> |
messi1 | 0:a1ed9ce625d4 | 26 | #include "PinNames.h" |
messi1 | 1:93710a3abf0a | 27 | #include "TMP007_Defs.h" |
messi1 | 0:a1ed9ce625d4 | 28 | |
messi1 | 0:a1ed9ce625d4 | 29 | |
messi1 | 0:a1ed9ce625d4 | 30 | class TMP007 |
messi1 | 0:a1ed9ce625d4 | 31 | { |
messi1 | 0:a1ed9ce625d4 | 32 | public: |
messi1 | 0:a1ed9ce625d4 | 33 | |
messi1 | 0:a1ed9ce625d4 | 34 | // Constructor |
messi1 | 0:a1ed9ce625d4 | 35 | TMP007(PinName sda, PinName scl, int addr); |
messi1 | 0:a1ed9ce625d4 | 36 | |
messi1 | 0:a1ed9ce625d4 | 37 | void writeConfig(const uint16_t value); |
messi1 | 0:a1ed9ce625d4 | 38 | uint16_t readConfig() ; |
messi1 | 0:a1ed9ce625d4 | 39 | |
messi1 | 0:a1ed9ce625d4 | 40 | uint16_t readStatus(); |
messi1 | 1:93710a3abf0a | 41 | void writeStatusMask(const uint16_t value); |
messi1 | 0:a1ed9ce625d4 | 42 | |
messi1 | 0:a1ed9ce625d4 | 43 | /** Configures sensor, use before reading from it */ |
messi1 | 0:a1ed9ce625d4 | 44 | void setSamples(const uint16_t samples); |
messi1 | 0:a1ed9ce625d4 | 45 | |
messi1 | 0:a1ed9ce625d4 | 46 | /** Read raw sensor temperature */ |
messi1 | 0:a1ed9ce625d4 | 47 | uint16_t readRawLocalTemperature(); |
messi1 | 0:a1ed9ce625d4 | 48 | |
messi1 | 0:a1ed9ce625d4 | 49 | /** Read raw thermopile voltage */ |
messi1 | 0:a1ed9ce625d4 | 50 | uint16_t readRawSensorVoltage(); |
messi1 | 0:a1ed9ce625d4 | 51 | |
messi1 | 0:a1ed9ce625d4 | 52 | /** Calculate object temperature (C) based on raw sensor temp and thermopile voltage */ |
messi1 | 0:a1ed9ce625d4 | 53 | double readObjTempC(); |
messi1 | 0:a1ed9ce625d4 | 54 | |
messi1 | 0:a1ed9ce625d4 | 55 | /** Calculate object temperature (F) based on raw sensor temp and thermopile voltage */ |
messi1 | 0:a1ed9ce625d4 | 56 | double readObjTempF(); |
messi1 | 0:a1ed9ce625d4 | 57 | |
messi1 | 0:a1ed9ce625d4 | 58 | /** Caculate sensor temperature (C) based on raw reading */ |
messi1 | 0:a1ed9ce625d4 | 59 | double readDieTempC(); |
messi1 | 0:a1ed9ce625d4 | 60 | |
messi1 | 0:a1ed9ce625d4 | 61 | /** Caculate sensor temperature (F) based on raw reading */ |
messi1 | 0:a1ed9ce625d4 | 62 | double readDieTempF(); |
messi1 | 0:a1ed9ce625d4 | 63 | |
messi1 | 0:a1ed9ce625d4 | 64 | private: |
messi1 | 0:a1ed9ce625d4 | 65 | /** |
messi1 | 0:a1ed9ce625d4 | 66 | * Writes a word value into the register. Note: the device must have the |
messi1 | 0:a1ed9ce625d4 | 67 | * auto-increment bit set in the MODE1 register to work. |
messi1 | 0:a1ed9ce625d4 | 68 | * |
messi1 | 0:a1ed9ce625d4 | 69 | * @param reg Register location to write into |
messi1 | 0:a1ed9ce625d4 | 70 | * @param word Word to write |
messi1 | 0:a1ed9ce625d4 | 71 | * @return True if successful |
messi1 | 0:a1ed9ce625d4 | 72 | */ |
messi1 | 0:a1ed9ce625d4 | 73 | bool writeWord(const uint8_t reg, const uint16_t word); |
messi1 | 0:a1ed9ce625d4 | 74 | |
messi1 | 0:a1ed9ce625d4 | 75 | /** |
messi1 | 0:a1ed9ce625d4 | 76 | * Read a word value from the register. Note: the device must have the |
messi1 | 0:a1ed9ce625d4 | 77 | * auto-increment bit set in the MODE1 register to work. |
messi1 | 0:a1ed9ce625d4 | 78 | * |
messi1 | 0:a1ed9ce625d4 | 79 | * @param reg Register location to read from |
messi1 | 0:a1ed9ce625d4 | 80 | * @return Value in the specified register |
messi1 | 0:a1ed9ce625d4 | 81 | */ |
messi1 | 0:a1ed9ce625d4 | 82 | uint16_t readWord(const uint8_t reg); |
messi1 | 0:a1ed9ce625d4 | 83 | |
messi1 | 0:a1ed9ce625d4 | 84 | private: |
messi1 | 0:a1ed9ce625d4 | 85 | mbed::I2C _i2cPort; |
messi1 | 0:a1ed9ce625d4 | 86 | uint8_t _addr; |
messi1 | 0:a1ed9ce625d4 | 87 | |
messi1 | 0:a1ed9ce625d4 | 88 | }; |
messi1 | 0:a1ed9ce625d4 | 89 | |
messi1 | 0:a1ed9ce625d4 | 90 | #endif |