Updated i2c interface to work correctly with mBed and Hexiwear
Dependents: Hexi_Click_IRThermo_Example
Fork of MLX90614 by
mlx90614.h@5:8f8aedd25609, 2016-10-27 (annotated)
- Committer:
- daveyclk
- Date:
- Thu Oct 27 20:06:15 2016 +0000
- Revision:
- 5:8f8aedd25609
- Parent:
- 4:dcd4fe76bd13
Completely re-written i2c interface as original did not work.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aquahika | 1:4a60d3f1e91e | 1 | #include "mbed.h" |
aquahika | 1:4a60d3f1e91e | 2 | |
aquahika | 1:4a60d3f1e91e | 3 | //Melexis Infrared Thermometer MLX90614 Library |
aquahika | 1:4a60d3f1e91e | 4 | |
aquahika | 1:4a60d3f1e91e | 5 | //***************************************************************** |
daveyclk | 5:8f8aedd25609 | 6 | // Build : 27/10/16 Dave Clarke |
aquahika | 1:4a60d3f1e91e | 7 | // Only read thermo data. |
aquahika | 1:4a60d3f1e91e | 8 | // |
aquahika | 1:4a60d3f1e91e | 9 | // This program does not check CRC. |
aquahika | 1:4a60d3f1e91e | 10 | // If you want to check CRC, please do it your self :) |
aquahika | 1:4a60d3f1e91e | 11 | //****************************************************************// |
aquahika | 1:4a60d3f1e91e | 12 | |
aquahika | 3:eb618e916622 | 13 | /**An Interface for MLX90614 |
aquahika | 3:eb618e916622 | 14 | * |
aquahika | 3:eb618e916622 | 15 | * @code |
aquahika | 2:01d333d06727 | 16 | * //Print temperature data |
aquahika | 2:01d333d06727 | 17 | * #include "mbed.h" |
aquahika | 2:01d333d06727 | 18 | * #include "mlx90614.h" |
aquahika | 2:01d333d06727 | 19 | * |
aquahika | 2:01d333d06727 | 20 | * I2C i2c(p28,p27); //sda,scl |
aquahika | 2:01d333d06727 | 21 | * MLX90614 thermometer(&i2c); |
aquahika | 4:dcd4fe76bd13 | 22 | * float temp; |
aquahika | 2:01d333d06727 | 23 | * |
aquahika | 2:01d333d06727 | 24 | * void main(void){ |
aquahika | 4:dcd4fe76bd13 | 25 | * if(thermometer.getTemp(&temp)){ |
aquahika | 2:01d333d06727 | 26 | * printf("Temperature : %f \r\n",temp); |
aquahika | 2:01d333d06727 | 27 | * } |
aquahika | 2:01d333d06727 | 28 | * wait(0.5); |
aquahika | 2:01d333d06727 | 29 | * |
aquahika | 2:01d333d06727 | 30 | * } |
aquahika | 3:eb618e916622 | 31 | * @endcode |
aquahika | 3:eb618e916622 | 32 | */ |
aquahika | 2:01d333d06727 | 33 | |
aquahika | 2:01d333d06727 | 34 | |
aquahika | 1:4a60d3f1e91e | 35 | class MLX90614{ |
aquahika | 1:4a60d3f1e91e | 36 | |
aquahika | 1:4a60d3f1e91e | 37 | public: |
aquahika | 2:01d333d06727 | 38 | /** Create MLX90614 interface, initialize with selected I2C port and address. |
aquahika | 2:01d333d06727 | 39 | * |
aquahika | 2:01d333d06727 | 40 | * @param i2c I2C device pointer |
aquahika | 2:01d333d06727 | 41 | * @param addr Device address(default=0xB4) |
aquahika | 2:01d333d06727 | 42 | */ |
daveyclk | 5:8f8aedd25609 | 43 | MLX90614(I2C* i2c,uint8_t addr=0xB4); |
aquahika | 2:01d333d06727 | 44 | |
aquahika | 2:01d333d06727 | 45 | /** Get Temperature data from MLX90614. |
aquahika | 2:01d333d06727 | 46 | * |
aquahika | 2:01d333d06727 | 47 | * @param temp_val return valiable pointer |
aquahika | 2:01d333d06727 | 48 | * @return 0 on success (ack), or non-0 on failure (nack) |
aquahika | 2:01d333d06727 | 49 | */ |
aquahika | 1:4a60d3f1e91e | 50 | bool getTemp(float* temp_val); |
aquahika | 1:4a60d3f1e91e | 51 | |
aquahika | 1:4a60d3f1e91e | 52 | private: |
aquahika | 1:4a60d3f1e91e | 53 | I2C* i2c; |
aquahika | 1:4a60d3f1e91e | 54 | int i2caddress; |
aquahika | 1:4a60d3f1e91e | 55 | |
daveyclk | 5:8f8aedd25609 | 56 | |
daveyclk | 5:8f8aedd25609 | 57 | |
aquahika | 0:9237d31f0d03 | 58 | }; |