Her is a sample code to read values from the Melexis MLX90614 I²C IR Thermometer. This thermometer is also available with 2 sensing areas and so the code reads 2 temperature values.
Datasheet
const
MLXTWIAddr : byte = $5A; // Melexis MLX90614
//MLX internal Adresses
MLX_RAM : byte = $00; //RAM Area
MLX_ROM : byte = $20; //ROM Area
MLX_FLAGS : byte = $F0; //READ Flags
MLX_SLEEP : byte = $FF; //Enter Sleep mode
MLX_TA : byte = $06; //Ambient Temperature
MLX_TObj1 : byte = $07; //Object-Temperature1
MLX_TObj2 : byte = $08; //Object-Temperature2
var
AmbTemp: float;
ObjTemp1: float;
ObjTemp2: float;
procedure ReadMLX;
var Data : array[0..2] of Byte;
raw : word;
PEC : Byte;
begin
if TWIstat(MLXTWIAddr) then
mdelay(50);
bool:= TWIOut(MLXTWIAddr, MLX_TA); // set read pointer to 6
bool:= TWIInp(MLXTWIAddr, Data);
if bool then
//Ambient-Temperature
HI(raw):= Data[1];
LO(raw):= Data[0];
PEC:= Data[2];
AmbTemp:= float(raw)*0.02 - 273.15;
endif;
bool:= TWIOut(MLXTWIAddr, MLX_TObj1); // set read pointer to 6
bool:= TWIInp(MLXTWIAddr, Data);
if bool then
//Object Temperature 1
HI(raw):= Data[1];
LO(raw):= Data[0];
PEC:= Data[2];
ObjTemp1:= float(raw)*0.02 - 273.15;
endif;
bool:= TWIOut(MLXTWIAddr, MLX_TObj2); // set read pointer to 6
bool:= TWIInp(MLXTWIAddr, Data);
if bool then
//Object Temperature 2
HI(raw):= Data[1];
LO(raw):= Data[0];
PEC:= Data[2];
ObjTemp2:= float(raw)*0.02 - 273.15;
endif;
endif;
end;
Datasheet
Code
const
MLXTWIAddr : byte = $5A; // Melexis MLX90614
//MLX internal Adresses
MLX_RAM : byte = $00; //RAM Area
MLX_ROM : byte = $20; //ROM Area
MLX_FLAGS : byte = $F0; //READ Flags
MLX_SLEEP : byte = $FF; //Enter Sleep mode
MLX_TA : byte = $06; //Ambient Temperature
MLX_TObj1 : byte = $07; //Object-Temperature1
MLX_TObj2 : byte = $08; //Object-Temperature2
var
AmbTemp: float;
ObjTemp1: float;
ObjTemp2: float;
procedure ReadMLX;
var Data : array[0..2] of Byte;
raw : word;
PEC : Byte;
begin
if TWIstat(MLXTWIAddr) then
mdelay(50);
bool:= TWIOut(MLXTWIAddr, MLX_TA); // set read pointer to 6
bool:= TWIInp(MLXTWIAddr, Data);
if bool then
//Ambient-Temperature
HI(raw):= Data[1];
LO(raw):= Data[0];
PEC:= Data[2];
AmbTemp:= float(raw)*0.02 - 273.15;
endif;
bool:= TWIOut(MLXTWIAddr, MLX_TObj1); // set read pointer to 6
bool:= TWIInp(MLXTWIAddr, Data);
if bool then
//Object Temperature 1
HI(raw):= Data[1];
LO(raw):= Data[0];
PEC:= Data[2];
ObjTemp1:= float(raw)*0.02 - 273.15;
endif;
bool:= TWIOut(MLXTWIAddr, MLX_TObj2); // set read pointer to 6
bool:= TWIInp(MLXTWIAddr, Data);
if bool then
//Object Temperature 2
HI(raw):= Data[1];
LO(raw):= Data[0];
PEC:= Data[2];
ObjTemp2:= float(raw)*0.02 - 273.15;
endif;
endif;
end;