MLX90614 library. Working on both Mbed2 and Mbed5

Dependents:   MLX90614_Demo

Fork of MLX90614 by Hikaru Sugiura

Committer:
masrodjie
Date:
Fri May 04 07:29:44 2018 +0000
Revision:
5:933b7db866c5
Parent:
2:01d333d06727
Fix library to working on latest Mbed2 & Mbed5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aquahika 1:4a60d3f1e91e 1
aquahika 1:4a60d3f1e91e 2 #include "mlx90614.h"
aquahika 1:4a60d3f1e91e 3
aquahika 2:01d333d06727 4
aquahika 2:01d333d06727 5
aquahika 2:01d333d06727 6
aquahika 1:4a60d3f1e91e 7 MLX90614::MLX90614(I2C* i2c,int addr){
aquahika 1:4a60d3f1e91e 8
aquahika 1:4a60d3f1e91e 9 this->i2caddress = addr;
aquahika 1:4a60d3f1e91e 10 this->i2c = i2c;
aquahika 1:4a60d3f1e91e 11
aquahika 1:4a60d3f1e91e 12 }
aquahika 1:4a60d3f1e91e 13
aquahika 1:4a60d3f1e91e 14
aquahika 1:4a60d3f1e91e 15 bool MLX90614::getTemp(float* temp_val){
aquahika 1:4a60d3f1e91e 16
masrodjie 5:933b7db866c5 17 char data[3];
aquahika 1:4a60d3f1e91e 18 float temp_thermo;
aquahika 1:4a60d3f1e91e 19
masrodjie 5:933b7db866c5 20 i2c->stop();
masrodjie 5:933b7db866c5 21 wait(0.02);
masrodjie 5:933b7db866c5 22 i2c->start();
aquahika 1:4a60d3f1e91e 23 wait(0.01);
masrodjie 5:933b7db866c5 24 data[0] = 0x00;
masrodjie 5:933b7db866c5 25 i2c->write((i2caddress<<1), data, 1, true);
masrodjie 5:933b7db866c5 26 wait(0.01);
masrodjie 5:933b7db866c5 27 data[0] = 0x07;
masrodjie 5:933b7db866c5 28 i2c->write((i2caddress<<1), data, 1, true);
masrodjie 5:933b7db866c5 29 wait(0.01);
masrodjie 5:933b7db866c5 30 i2c->read(((i2caddress<<1)|0x01), data, 3, true);
masrodjie 5:933b7db866c5 31 wait(0.01);
masrodjie 5:933b7db866c5 32 i2c->stop(); //stop condition
aquahika 1:4a60d3f1e91e 33
aquahika 1:4a60d3f1e91e 34
masrodjie 5:933b7db866c5 35 temp_thermo=((((data[1]&0x007f)<<8)+data[0])*0.02)-0.01; //degree centigrate conversion
aquahika 1:4a60d3f1e91e 36 *temp_val=temp_thermo-273; //Convert kelvin to degree Celsius
aquahika 1:4a60d3f1e91e 37
aquahika 1:4a60d3f1e91e 38 return true; //load data successfully, return true
aquahika 1:4a60d3f1e91e 39 }