The repo is here: https://github.com/nseidle/MLX90620_Example

One main improvement was the removal of float v_ir_tgc_comp[64]. v_ir_tgc_comp is only calculated once so an array of floats can be removed. This saves a good pile (256bytes) of RAM.

Let me know if you see any problems or changes that can be made. This is a neat (but expensive!) little sensor.

-Nathan

Code:

//Calculate the temperatures seen for each pixel

//Relies on the raw irData array

//Returns an 64-int array called temperatures

void calculate_TO()

{

float v_ir_off_comp;

float v_ir_tgc_comp;

float v_ir_comp;

//Calculate the offset compensation for the one compensation pixel

//This is a constant in the TO calculation, so calculate it here.

int cpix = readCPIX_MLX90620(); //Go get the raw data of the compensation pixel

float v_cp_off_comp = (float)cpix - (a_cp + (b_cp/pow(2, b_i_scale)) * (Tambient - 25));

for (int i = 0 ; i < 64 ; i++)

{

v_ir_off_comp = irData[i] - (a_ij[i] + (float)(b_ij[i]/pow(2, b_i_scale)) * (Tambient - 25)); //#1: Calculate Offset Compensation

v_ir_tgc_comp = v_ir_off_comp - ( ((float)tgc/32) * v_cp_off_comp); //#2: Calculate Thermal Gradien Compensation (TGC)

v_ir_comp = v_ir_tgc_comp / emissivity; //#3: Calculate Emissivity Compensation

temperatures[i] = sqrt( sqrt( (v_ir_comp/alpha_ij[i]) + pow(Tambient + 273.15, 4) )) - 273.15;

}

}

//Relies on the raw irData array

//Returns an 64-int array called temperatures

void calculate_TO()

{

float v_ir_off_comp;

float v_ir_tgc_comp;

float v_ir_comp;

//Calculate the offset compensation for the one compensation pixel

//This is a constant in the TO calculation, so calculate it here.

int cpix = readCPIX_MLX90620(); //Go get the raw data of the compensation pixel

float v_cp_off_comp = (float)cpix - (a_cp + (b_cp/pow(2, b_i_scale)) * (Tambient - 25));

for (int i = 0 ; i < 64 ; i++)

{

v_ir_off_comp = irData[i] - (a_ij[i] + (float)(b_ij[i]/pow(2, b_i_scale)) * (Tambient - 25)); //#1: Calculate Offset Compensation

v_ir_tgc_comp = v_ir_off_comp - ( ((float)tgc/32) * v_cp_off_comp); //#2: Calculate Thermal Gradien Compensation (TGC)

v_ir_comp = v_ir_tgc_comp / emissivity; //#3: Calculate Emissivity Compensation

temperatures[i] = sqrt( sqrt( (v_ir_comp/alpha_ij[i]) + pow(Tambient + 273.15, 4) )) - 273.15;

}

}