Intermediate
30 min
0

Detect the infrared energy of various objects with MLX90640-BAB and PIC18LF45K22

From cold to bold: The thermal imaging solution you've been waiting for!

IR Grid 2 click with Curiosity HPC

Published Nov 01, 2023

Click board™

IR Grid 2 click

Development board

Curiosity HPC

Compiler

NECTO Studio

MCU

PIC18LF45K22

Navigate with confidence in diverse environments and conditions, as our thermal imaging technology delivers accurate, real-time temperature data, enabling you to identify issues, monitor trends, and respond swiftly

A

A

Hardware Overview

How does it work?

IR Grid 2 Click is based on the MLX90640, a 32x24 IR array sensor from Melexis. This sensor contains 8 Kbit EEPROM, used to store all the compensation and calibration parameters, along with some editable user parameters, such as the config registers, I2C address and similar. These sensors can measure temperature relative to the cold junction temperature, and for this reason, the MLX90640ESF-BAB IR sensor incorporates a PTAT (Proportional to Absolute Temperature) compensation sensor. The device also contains the power supply voltage measurement feature, allowing power supply monitoring. It is recommended that the supply voltage stay as accurate as possible, which is taken care of if used with the MikroElektronika development systems. The IR sensor array, as well as the PTAT sensor readings, are sampled by the internal Analog to Digital Converter (ADC) and stored to RAM, which can be accessed via the I2C interface. The resolution of the ADC can be programmed between 16 bits and 19bits. The MLX90640ESF-BAB IR sensor used on this Click board™ has a Field of View (FOV) of 55˚x32˚, with the IR sensing elements arranged in a 32x28 grid. Each sensor measures the temperature in its individual FOV, allowing the host MCU to build a thermal image or calculate the temperature at each spot of the viewed scene. The measurement results are stored to RAM. The entire RAM area is divided in two pages, with access patterns controlled by the configuration registers (chess pattern, or

interleaved pattern). The compensation parameters stored in the EEPROM are factory calibrated for chess pattern access, yielding the most accurate results when using this mode. The chess pattern mode is selected by default. The configuration and control registers allow to set the operational parameters of the IR grid sensor. These registers contain bits that control the behavior of the sensor IC: the refresh rate, the ADC resolution, measurement mode (continuous or step mode), sleep mode, I2C mode (FM or FM+), and more. On restart, the data from the corresponding copies of these register locations in EEPROM is mirrored to the operational register locations in RAM, preparing the device to be instantly operated. This allows changing of the default values, since they are actually stored in EEPROM, rather than being hard-coded into the device. Besides the default working parameters, the EEPROM area contains all the compensation parameters for each IR element, necessary for completing the accurate thermal calculations. Those calculations include ambient temperature calculation, pixel offset calculation, pixel to pixel sensitivity difference compensation, object emissivity compensation, and object temperature calculation. The datasheet of the MLX90640ESF-BAB IR sensor contains equations which use these parameters stored in EEPROM. However, this Click board™ is supplied with the library, which contains functions that simplify working with this sensor, saving time. Two modes of operation are available: the device can

continuously sample data from the IR elements, with the programmed refresh rate (up to 64 frames per second), or it can take one frame, by sampling the selected page. The status byte contains flags that indicate that the reading of a specific page is done. It should be noted that the sensor measures the IR emissivity of an object, so it is to be expected that some materials cannot be accurately measured by this sensor due to their low emissivity, such as the aluminum. To better understand the emissivity property of the materials, a person wearing clothes, can be taken as an example: the measured temperature will reflect the clothes temperature, rather than the body temperature itself, which is known to be about 37 ˚C Care should be taken not to expose the Click board™ to a cold or hot air flow, as it will cause false readings of the real temperature. This sensor requires the temperature across the sensor package to be constant. The MLX90640ESF-BAB IR sensor uses 3.3V for optimal results. While the power for the IR sensor itself is taken from the 3.3V mikroBUS™ rail, in order to support MCUs which use 5V compatible logic levels, the Click board™ comes equipped with PCA9306, a bi-directional I2C level translator IC, produced by Texas Instruments. This allows the logic voltage level to be selected by the SMD jumper labeled as VCC SEL. Besides I2C bus lines, no additional lines of the mikroBUS™ are used. I2C bus lines are routed to the respective pins of the mikroBUS™.

IR Grid 2 Click top side image
IR Grid 2 Click bottom side image

Features overview

Development board

Curiosity HPC, standing for Curiosity High Pin Count (HPC) development board, supports 28- and 40-pin 8-bit PIC MCUs specially designed by Microchip for the needs of rapid development of embedded applications. This board has two unique PDIP sockets, surrounded by dual-row expansion headers, allowing connectivity to all pins on the populated PIC MCUs. It also contains a powerful onboard PICkit™ (PKOB), eliminating the need for an external programming/debugging tool, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, a set of indicator LEDs, push button switches and a variable potentiometer. All

these features allow you to combine the strength of Microchip and Mikroe and create custom electronic solutions more efficiently than ever. Each part of the Curiosity HPC development board contains the components necessary for the most efficient operation of the same board. An integrated onboard PICkit™ (PKOB) allows low-voltage programming and in-circuit debugging for all supported devices. When used with the MPLAB® X Integrated Development Environment (IDE, version 3.0 or higher) or MPLAB® Xpress IDE, in-circuit debugging allows users to run, modify, and troubleshoot their custom software and hardware

quickly without the need for additional debugging tools. Besides, it includes a clean and regulated power supply block for the development board via the USB Micro-B connector, alongside all communication methods that mikroBUS™ itself supports. Curiosity HPC development board allows you to create a new application in just a few steps. Natively supported by Microchip software tools, it covers many aspects of prototyping thanks to many number of different Click boards™ (over a thousand boards), the number of which is growing daily.

Curiosity HPC double image

Microcontroller Overview

MCU Card / MCU

PIC18LF45K22

Architecture

PIC

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

1536

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

IR Grid 2 click Schematic schematic

Step by step

Project assembly

Curiosity HPC front no-mcu image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity HPC as your development board.

Curiosity HPC front no-mcu image hardware assembly
Thermo 28 Click front image hardware assembly
MCU DIP 40 hardware assembly
Prog-cut hardware assembly
Curiosity HPC MB 1 - upright/with-background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for IR Grid 2 Click driver.

Key functions:

  • irgrid2_generic_write - This function reads a desired number of data bytes starting from the selected register by using I2C serial interface

  • irgrid2_get_frame_data - This function is used for getting frame data

  • irgrid2_get_pixel_temperature - This function is used for getting pixels temperature

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief IRGrid2 Click example
 *
 * # Description
 * The demo application displays a reading of ambient temperature and 
 * a 32x24 pixel object temperature matrix.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Configures the click and log objects and sets the click default configuration.
 * 
 * ## Application Task  
 * Reads the temperature of all pixels every 500ms 
 * and displays it on USB UART in a form of a 32x24 matrix.
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "irgrid2.h"

static irgrid2_t irgrid2;
static log_t logger;

void application_init ( void ) {
    log_cfg_t log_cfg;  /**< Logger config object. */
    irgrid2_cfg_t irgrid2_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    // Click initialization.
    irgrid2_cfg_setup( &irgrid2_cfg );
    IRGRID2_MAP_MIKROBUS( irgrid2_cfg, MIKROBUS_1 );
    err_t init_flag = irgrid2_init( &irgrid2, &irgrid2_cfg );
    if ( I2C_MASTER_ERROR == init_flag ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    irgrid2_default_cfg ( &irgrid2 );
    Delay_ms( 1000 );
    log_info( &logger, "---- Start measurement ----" );
}

void application_task ( void ) {
    float px_matrix[ 768 ];
    float temp_ambient;

    irgrid2_get_pixel_temperature( &irgrid2, &temp_ambient, px_matrix );

    log_printf( &logger, "\r\n>> Pixel temperature matrix 32x24 <<\r\n" );
    for ( uint16_t cnt = 1 ; cnt < 769 ; cnt++) {
        log_printf( &logger, "%.2f", px_matrix[ cnt - 1 ] );
        if ( ( ( cnt % 32 ) == 0 ) ) {
            log_printf( &logger, "\r\n" );
        } else {
            log_printf( &logger, " | " );
        }
    }
    log_printf( &logger, "\r\n** Ambient (sensor) temperature is %.2f Celsius\r\n", temp_ambient );
    Delay_ms( 500 );
}

void main ( void ) {
    application_init( );

    for ( ; ; ) {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources