コード例 #1
0
ファイル: mlx90620.c プロジェクト: konstantinwerner/sensors
void setup()
{
    Serial.begin(115200);
    Serial.println("MLX90620 Example");

    i2c_init(); //Init the I2C pins
    PORTC = (1 << PORTC4) | (1 << PORTC5); //Enable pull-ups

    delay(5); //Init procedure calls for a 5ms delay after power-on

    read_EEPROM_MLX90620(); //Read the entire EEPROM

    setConfiguration(refreshRate); //Configure the MLX sensor with the user's choice of refresh rate

    calculate_TA(); //Calculate the current Tambient
}
コード例 #2
0
ファイル: mlx90620.c プロジェクト: ameya005/openmv
static void mlx90620_read_to(float *t)
{
    float v_ir_comp;
    float v_ir_off_comp;
    float v_ir_tgc_comp;

    int16_t cpix;
    uint8_t cmd_buf[4];
    int16_t ir_data[64];

//    static int count=0;
//    if (count++ %16 ==0) {
    float Ta = calculate_TA();
    // (T+273.15f)^4
    float Ta4 = (Ta + 273.15f) * (Ta + 273.15f) * (Ta + 273.15f) * (Ta + 273.15f);
  //  }

    // Read IR data
    memcpy(cmd_buf, (uint8_t [4]){MLX_READ_REG, 0x00, 0x01, 0x40}, sizeof(cmd_buf)); //read 64*2 bytes
    soft_i2c_write_bytes(MLX_SLAVE_ADDR, cmd_buf, sizeof(cmd_buf), false);
    soft_i2c_read_bytes(MLX_SLAVE_ADDR, (uint8_t*)ir_data, 128, true);

    // Read compensation data
    memcpy(cmd_buf, (uint8_t [4]){MLX_READ_REG, 0x91, 0x00, 0x01}, sizeof(cmd_buf));
    soft_i2c_write_bytes(MLX_SLAVE_ADDR, cmd_buf, sizeof(cmd_buf), false);
    soft_i2c_read_bytes(MLX_SLAVE_ADDR, (uint8_t*)&cpix, 2, true);

    //Calculate the offset compensation for the one compensation pixel
    //This is a constant in the TO calculation, so calculate it here.
    float v_cp_off_comp = (float)cpix - (a_cp + (b_cp/(2<<(b_i_scale-1))) * (Ta - 25));

    for (int i=0; i<64; i++) {
        //#1: Calculate Offset Compensation
        v_ir_off_comp = ir_data[i] - (a_ij[i] + (float)(b_ij[i]/(2<<(b_i_scale-1))) * (Ta - 25));

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

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

        t[i] = fast_sqrtf(fast_sqrtf(v_ir_comp/alpha_ij[i] + Ta4)) - 273.15f;
    }
}
コード例 #3
0
ファイル: mlx90620.c プロジェクト: konstantinwerner/sensors
void loop()
{
    if(loopCount++ == 16) //Tambient changes more slowly than the pixel readings. Update TA only every 16 loops.
    {
        calculate_TA(); //Calculate the new Tambient

        if(checkConfig_MLX90620()) //Every 16 readings check that the POR flag is not set
        {
            Serial.println("POR Detected!");
            setConfiguration(refreshRate); //Re-write the configuration bytes to the MLX
        }

        loopCount = 0; //Reset count
    }

    readIR_MLX90620(); //Get the 64 bytes of raw pixel data into the irData array

    calculate_TO(); //Run all the large calculations to get the temperature data for each pixel

    prettyPrintTemperatures(); //Print the array in a 4 x 16 pattern
    //rawPrintTemperatures(); //Print the entire array so it can more easily be read by Processing app
}