Einstein Filho
/
MLX90614
Mangue Baja Personalized MLX program
MLX90614.h@2:5e50e3dd1d17, 2019-08-01 (annotated)
- Committer:
- einsteingustavo
- Date:
- Thu Aug 01 11:43:08 2019 +0000
- Revision:
- 2:5e50e3dd1d17
- Parent:
- 1:494ed2723916
Mangue Baja Personalized MLX program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jensstruemper | 0:755bd47fd6be | 1 | /* |
jensstruemper | 0:755bd47fd6be | 2 | Copyright (c) 2016 Jens Strümper based on the work of Jonathan Jones. |
jensstruemper | 0:755bd47fd6be | 3 | |
jensstruemper | 0:755bd47fd6be | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
jensstruemper | 0:755bd47fd6be | 5 | of this software and associated documentation files (the "Software"), to deal |
jensstruemper | 0:755bd47fd6be | 6 | in the Software without restriction, including without limitation the rights |
jensstruemper | 0:755bd47fd6be | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
jensstruemper | 0:755bd47fd6be | 8 | copies of the Software, and to permit persons to whom the Software is |
jensstruemper | 0:755bd47fd6be | 9 | furnished to do so, subject to the following conditions: |
jensstruemper | 0:755bd47fd6be | 10 | |
jensstruemper | 0:755bd47fd6be | 11 | The above copyright notice and this permission notice shall be included in |
jensstruemper | 0:755bd47fd6be | 12 | all copies or substantial portions of the Software. |
jensstruemper | 0:755bd47fd6be | 13 | |
jensstruemper | 0:755bd47fd6be | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
jensstruemper | 0:755bd47fd6be | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
jensstruemper | 0:755bd47fd6be | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
jensstruemper | 0:755bd47fd6be | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
jensstruemper | 0:755bd47fd6be | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
jensstruemper | 0:755bd47fd6be | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
jensstruemper | 0:755bd47fd6be | 20 | THE SOFTWARE. |
jensstruemper | 0:755bd47fd6be | 21 | */ |
jensstruemper | 0:755bd47fd6be | 22 | |
jensstruemper | 0:755bd47fd6be | 23 | #ifndef MLX90614_H |
jensstruemper | 0:755bd47fd6be | 24 | #define MLX90614_H |
jensstruemper | 0:755bd47fd6be | 25 | |
jensstruemper | 0:755bd47fd6be | 26 | #ifndef MBED_H |
jensstruemper | 0:755bd47fd6be | 27 | #include "mbed.h" |
jensstruemper | 0:755bd47fd6be | 28 | #endif |
jensstruemper | 0:755bd47fd6be | 29 | |
jensstruemper | 0:755bd47fd6be | 30 | namespace js { |
jensstruemper | 0:755bd47fd6be | 31 | |
jensstruemper | 0:755bd47fd6be | 32 | /** Due to changes in mbed's I2C stack older implementation of the MLX9064 library do currently not work. |
jensstruemper | 0:755bd47fd6be | 33 | * This recent implementation wraps the example code of Jonathan Jones into a library. |
jensstruemper | 0:755bd47fd6be | 34 | * |
jensstruemper | 0:755bd47fd6be | 35 | * The float read_temp(int select) memeber function will take one argument: |
jensstruemper | 0:755bd47fd6be | 36 | * <ul> |
jensstruemper | 0:755bd47fd6be | 37 | * <li> "0" to return ambient temperature </li> |
jensstruemper | 0:755bd47fd6be | 38 | * <li> "1" to retunr object temperature </li> |
jensstruemper | 0:755bd47fd6be | 39 | * </ul> |
jensstruemper | 0:755bd47fd6be | 40 | * |
jensstruemper | 0:755bd47fd6be | 41 | * Example: |
jensstruemper | 0:755bd47fd6be | 42 | * @code |
jensstruemper | 0:755bd47fd6be | 43 | * #include "mbed.h" |
jensstruemper | 0:755bd47fd6be | 44 | * #include "MLX90614.h" |
jensstruemper | 0:755bd47fd6be | 45 | * |
jensstruemper | 0:755bd47fd6be | 46 | * I2C i2c(p16, p17); //I2C_SDA, I2C_SCL |
jensstruemper | 0:755bd47fd6be | 47 | * MLX90614 mlx90614(&i2c); |
jensstruemper | 0:755bd47fd6be | 48 | * |
jensstruemper | 0:755bd47fd6be | 49 | * float temp; |
jensstruemper | 0:755bd47fd6be | 50 | * int select; // 0 = object temp, 1 = ambient temp |
jensstruemper | 0:755bd47fd6be | 51 | * |
jensstruemper | 0:755bd47fd6be | 52 | * int main(){ |
jensstruemper | 0:755bd47fd6be | 53 | while(true){ |
jensstruemper | 0:755bd47fd6be | 54 | temp=mlx90614.read_temp(1); |
jensstruemper | 0:755bd47fd6be | 55 | printf("%4.2f Celcius\r\n", temp); |
jensstruemper | 0:755bd47fd6be | 56 | wait(1); |
jensstruemper | 0:755bd47fd6be | 57 | } |
jensstruemper | 0:755bd47fd6be | 58 | } |
jensstruemper | 0:755bd47fd6be | 59 | * @endcode |
jensstruemper | 0:755bd47fd6be | 60 | */ |
jensstruemper | 0:755bd47fd6be | 61 | |
jensstruemper | 0:755bd47fd6be | 62 | class MLX90614 { |
jensstruemper | 0:755bd47fd6be | 63 | |
jensstruemper | 0:755bd47fd6be | 64 | public: |
jensstruemper | 0:755bd47fd6be | 65 | |
jensstruemper | 0:755bd47fd6be | 66 | MLX90614(PinName sda, PinName scl); |
jensstruemper | 0:755bd47fd6be | 67 | |
jensstruemper | 0:755bd47fd6be | 68 | MLX90614(I2C *i2c); |
jensstruemper | 0:755bd47fd6be | 69 | |
jensstruemper | 0:755bd47fd6be | 70 | ~MLX90614(); |
jensstruemper | 0:755bd47fd6be | 71 | |
jensstruemper | 0:755bd47fd6be | 72 | float read_temp(int select); |
jensstruemper | 0:755bd47fd6be | 73 | |
jensstruemper | 0:755bd47fd6be | 74 | protected: |
jensstruemper | 0:755bd47fd6be | 75 | |
jensstruemper | 0:755bd47fd6be | 76 | float get_temp(uint8_t reg); |
jensstruemper | 0:755bd47fd6be | 77 | |
jensstruemper | 0:755bd47fd6be | 78 | private: |
jensstruemper | 0:755bd47fd6be | 79 | |
jensstruemper | 0:755bd47fd6be | 80 | I2C *i2c_; |
jensstruemper | 0:755bd47fd6be | 81 | |
einsteingustavo | 1:494ed2723916 | 82 | static const int default_addr = 0x0E; |
jensstruemper | 0:755bd47fd6be | 83 | static const int T_ambient = 0x06; |
jensstruemper | 0:755bd47fd6be | 84 | static const int T_obj1 = 0x07; |
einsteingustavo | 1:494ed2723916 | 85 | static const int ram_access = 0x04; |
jensstruemper | 0:755bd47fd6be | 86 | |
jensstruemper | 0:755bd47fd6be | 87 | }; |
jensstruemper | 0:755bd47fd6be | 88 | |
jensstruemper | 0:755bd47fd6be | 89 | } //namespace js |
jensstruemper | 0:755bd47fd6be | 90 | |
jensstruemper | 0:755bd47fd6be | 91 | using namespace js; |
jensstruemper | 0:755bd47fd6be | 92 | |
jensstruemper | 0:755bd47fd6be | 93 | #endif |