Labs / Electronic modules

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation, v1.3 · License: CC BY 4.0 · Driver code (sensors/mlx90640_driver): MIT License

Contents
GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)
GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

I. Module Introduction

Contactless infrared image sensor module based on MLX90640 chip A thermal infrared array sensor module based on a 32×24 pixel array, adopting TO39 package, featuring a noise equivalent temperature difference performance of 0.1K RMS @ 1Hz refresh rate, and supporting I²C communication.The module operates at a voltage of 3.3V with a current consumption of less than 23mA, features a programmable refresh rate ranging from 0.5Hz to 64Hz, offers two optional fields of view: 55°×35° and 110°×75°, has an operating temperature range of -40°C to 85°C, supports target temperature measurement from -40°C to + 300°C, and complies with the RoHS directive. It is suitable for scenarios such as non-contact temperature detection and thermal imaging analysis, providing accurate infrared image sensing solutions for industrial monitoring, smart home and other fields.

II. Introduction to Main Chips

MLX90640 is an industrial-grade calibrated thermal infrared array sensor launched by Melexis, which features a total of 768 pixels in a 32×24 resolution, a wide temperature measurement range from -40°C to 300°C, a typical temperature measurement accuracy of approximately ±1°C, a noise equivalent temperature difference of only 0.1K at a 1Hz refresh rate, and optional field-of-view angles of 55°×35° and 110°×75° to adapt to different ranging scenarios, enabling continuous operation without additional calibration.It is equipped with an I²C-compatible digital interface supporting a maximum communication rate of 1MHz, and incorporates a built-in ambient temperature sensor and voltage detection ADC, which enables it to read a variety of real-time data via the interface. It can be easily integrated into various embedded systems, and is widely used in non-contact thermal imaging and temperature measurement scenarios such as industrial temperature measurement, intelligent buildings, and security monitoring.

2.1 Chip Overview

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)
GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

2.2 Pin Definition

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

2.3 Functional Block Diagram

None.

2.4 Performance Parameters

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)
GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)
GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)
GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)
GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

Some of the data in the above table are shown as follows:

2.5 Reference Circuit

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

In this MLX90640 reference circuit, the sensor is powered by 3.3V, with 10μF and 100nF capacitors to filter power supply ripple for stable power delivery; its SDA and SCL pins are pulled up via 1kΩ resistors and then connected to the MCU, which not only maintains the idle level of the I2C bus but also adapts to the level difference between devices; meanwhile, the sensor, capacitors and the MCU share a common ground to eliminate potential difference, collectively achieving stable power supply and reliable I2C communication.

2.6 Chip Configuration

None.

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)
GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)
GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

The MLX90640 adopts I2C communication, with a default slave address of 0x33.

MLX90640 allows users to configure its measurement mode and refresh rate, a brief description of which is provided below:

  1. Measurement Mode: The device operates continuously, and based on the frame rate set in the control register Fps, updates the infrared pixels and ambient temperature (Ta) data in RAM every 1 second at the rate of Fps, and the host can access its internal registers/memory.
  2. Refresh rate: Configured via Control Register 1 (0x800D)(e. g., "011" corresponds to 4Hz, updating subpage data in RAM every 250ms); the configuration can also be written to EEPROM (0x240C) for power-off retention. Calculation of Ta (Ta update rate is 1/2 of the refresh rate) requires reading data from two subpages. The "new data available" bit in the Status Register (0x8000) indicates subpage update, and this bit must be reset after reading.

2.8 PCB Routing Precautions

None.

III. Circuit Engineering

3.1 Circuit Source Engineering

To obtain the source code of the circuit, please follow the official account [Freak Embedded]

3.2 Module Usage Instructions

SCH_Schematic1_MLX90640-Based Non-Contact Infrared Image Sensor Module_v1.0_2025-11-11.pdf 2.0 MB

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

This module provides an I2C communication interface: it supports standard I2C communication rate, with a default I2C address of 0x33, is compatible with 3.3V logic level, and can stably transmit thermal infrared array data of 32×24 pixels (including target temperature information ranging from -40°C to + 300°C). It can also transmit configuration commands such as programmable refresh rate (0.5Hz to 64Hz), and is suitable for scenarios including non-contact temperature detection, thermal imaging analysis, and industrial equipment monitoring, providing accurate thermal data interaction capabilities for infrared sensing applications.

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

As we can see, each infrared detection point (pixel) on the module is denoted by Pix (i, j). When retrieving data, we only need to use "row number i (1-24) + column number j (1-32)" to accurately map to a specific detection position on the module.

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

Meanwhile, note that the module splits and stores the data of 768 sensors into two data subpages: " Subpage 0 (corresponding to address 0x8000= 0xXXX8)" and " Subpage 1 (corresponding to address 0x8000= 0xXXX9)"; regardless of the mode, each time a read is triggered, only the data of the highlighted cells (corresponding to sensors) in the diagram will be updated in real time, while the non-highlighted cells will retain their previous values:

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

Furthermore, for different models of the MLX90640 probe, their accuracy partitioning also varies:

Briefly, when selecting a model: if you need accuracy to cover corner areas, prioritize BAB; when using the module, no matter which model it is, try to align the core detection target with its respective Zone1 area to obtain optimal data.

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

Field of view (FOV) refers to the angular range within which the sensor maintains effective detection sensitivity — in the curve on the right, the angular interval where the incident angle of the heat source corresponds to a sensor sensitivity of ≥50% is defined as FOV; when directly facing the sensor (incident angle = 0°), the sensitivity reaches 100%, delivering the optimal detection performance.

When arranging the detection target, try to align the heat source with the directly front of the sensor (incident angle of 0°), as this yields the highest sensitivity and the most accurate data; if heat sources at different angles need to be detected, be sure that the target stays within the angle range of the FOV to avoid detection failure caused by out-of-limit angles.

3.3 Application Experiment

Here, we use the GraftPort-RP2040 development board for testing, and the non-contact infrared image sensor module based on the MLX90640 chip uses the I2C interface to communicate with the main controller.

Here, we first use the HY2.0-4P cable to connect the module to the GraftPort-RP2040 development board's I2C0 interface:

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

The module connections are shown in the following table:

Development Board Pins

Module Pins

Description

Pin 4

SDA

I2C data transmission line, corresponding to the I2C0 SDA

Pin 5

SCL

I2C clock signal line, corresponding to I2C0 's SCL

Here, we need to search for relevant driver packages on uPyPI: https://upypi.net/zh/

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

Enter mlx_90640_driver to search, and the following will be displayed:

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

Click to copy the local installation command:

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

Here, we can use the mip tool to import module driver library code. Below are the usage commands for the mpremote tool:

mpremote mip install github:FreakStudioCN/GraftSense-Drivers-MicroPython/sensors/mlx90640_driver

Import the contactless infrared image sensor module based on the MLX90640 chip - MicroPython driver code, then copy the following main.py code into our project:

# Python env   : MicroPython v1.23.0
# -*- coding: utf-8 -*-
# @Time    : 2025/8/27 11:50 AM
# @Author  : 缪贵成
# @File    : main.py
# @Description : mlx90614 dual-zone temperature sensor test file

# ======================================== Import Modules =========================================

import time
from machine import I2C, Pin
from mlx90614 import MLX90614, MLX90615

# ======================================== Global Variables =============================================

mlx61xaddr=None

# ======================================== Functions =============================================

def test_sensor_realtime(sensor, name="Sensor", interval=1.0):
    """

    Display sensor temperature data in real time, covering all function tests.
    Args:
        sensor: MLX90614 or MLX90615 sensor instance
        name: Sensor name, used for output labeling
        interval: Data refresh interval, in seconds

    Notes:
        The tests cover internal methods, public methods, property access, and one-shot read functionality
        Dual-zone sensors additionally display the second object temperature channel
        Internal method tests may vary depending on the sensor model

    ==========================================

    Realtime display of sensor temperature data, covering all functional tests.

    Args:
        sensor: Instance of MLX90614 or MLX90615 sensor
        name: Sensor name for output identification
        interval: Data refresh interval in seconds

    Notes:
        Tests include internal methods, public methods, property access and one-time read function
        Dual-zone sensors will additionally display the second object temperature data
        Internal method tests may vary by sensor model
    """
    print("\n=== Realtime testing {} ===".format(name))
    print("Dual zone:", sensor.dual_zone)  # Output whether the sensor is dual-zone
    print("Press Ctrl+C to stop")  # Prompt the user that Ctrl+C can be used to stop the test

    try:
        while True:
            # ================= Internal Method Tests =================
            try:
                # Read the raw register value (16-bit)
                raw_ambient = sensor._read16(sensor._REGISTER_TA)
                raw_object = sensor._read16(sensor._REGISTER_TOBJ1)

                # Convert the raw register value to degrees Celsius
                temp_ambient_internal = sensor._read_temp(sensor._REGISTER_TA)
                temp_object_internal = sensor._read_temp(sensor._REGISTER_TOBJ1)
            except Exception as e:
                print("[Internal] Error:", e)
                raw_ambient = raw_object = temp_ambient_internal = temp_object_internal = None

            # ================= Public Method Tests =================
            ambient = sensor.read_ambient()  # Read ambient temperature
            obj = sensor.read_object()       # Read object temperature
            # For dual-zone sensors, read the second object temperature; otherwise None
            obj2 = sensor.read_object2() if sensor.dual_zone else None

            # ================= Property Access Tests =================
            ambient_prop = sensor.ambient
            obj_prop = sensor.object
            obj2_prop = sensor.object2 if sensor.dual_zone else None

            # ================= One-Shot Read Function Tests =================
            try:
                all_data = sensor.read()  # Read all data at once (returns a dict)
            except Exception as e:
                all_data = None

            # ================= Data Output =================
            print("\n[{}] Data Snapshot".format(name))
            print("Raw ambient (internal):", raw_ambient)
            print("Raw object (internal):", raw_object)
            if temp_ambient_internal is not None:
                print("Temp ambient via _read_temp: {:.2f} °C".format(temp_ambient_internal))
            if temp_object_internal is not None:
                print("Temp object via _read_temp: {:.2f} °C".format(temp_object_internal))
            print("Ambient: {:.2f} °C".format(ambient))
            print("Object: {:.2f} °C".format(obj))
            if sensor.dual_zone:
                print("Object2: {:.2f} °C".format(obj2))
            print("Property ambient: {:.2f} °C".format(ambient_prop))
            print("Property object: {:.2f} °C".format(obj_prop))
            if sensor.dual_zone:
                print("Property object2: {:.2f} °C".format(obj2_prop))
            print("Read all:", all_data)

            # Wait for a while before refreshing
            time.sleep(interval)

    except KeyboardInterrupt:
        # Exit the loop when the user presses Ctrl+C
        print("\nRealtime testing stopped")

# ======================================== Custom Classes =============================================

# ======================================== Initialization configuration ===========================================

# Hardware power-on delay to ensure the sensor has finished initializing
time.sleep(3)
print("FreakStudio: MLX90614 test start ")
# ================= I2C Initialization =================
i2c = I2C(0, scl=5, sda=4, freq=100000)
# Start scanning for devices on the I2C bus and return a list of slave addresses
devices_list: list[int] = i2c.scan()
print('START I2C SCANNER')
# If the devices list is empty, no device is connected to the I2C bus
if len(devices_list) == 0:
    # If not empty, print the slave device addresses
    print("No i2c device !")
else:
    print('i2c devices found:', len(devices_list))
for device in devices_list:
    if 0x5A <= device <= 0x5D:
        print("I2c hexadecimal address:", hex(device))
        mlx61xaddr = device

# Initialize MLX90614
sensor14 = MLX90614(i2c, mlx61xaddr)
print("[MLX90614] Sensor initialized.")
# Initialize MLX90615
sensor15 = MLX90615(i2c, mlx61xaddr)
print("[MLX90615] Sensor initialized.")

# ======================================== Main Program ==============================================

# ================= MLX90614 Test =================
print("\n--- Starting MLX90614 Realtime Test ---")
test_sensor_realtime(sensor14, "MLX90614", interval=1.0)

# ================= MLX90615 Test =================
print("\n--- Starting MLX90615 Realtime Test ---")
test_sensor_realtime(sensor15, "MLX90615", interval=1.0)

To flash the code, open a terminal and use the mpremote tool to connect to the main controller; the output is as follows:

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)

It can be seen that as we wave our hand directly above the sensor module, the terminal outputs the temperature pixel values of the 4×4 area, and meanwhile counts the minimum, maximum and average values of the current temperature: -

IV. Drivers

mlx90640_driver.zip 25 KB

None.

VI. Revision History

Document Version

Date of Revision

Modifier

Revised Content

v1.0

2025-11-11

Zero Kōkō

Initialize the document

v1.1

2025-12-29

Li Zisheng

Added application experiments and production files

v1.2

2025-12-31

Xin Ruili

Create an open version of the document based on the internal document version v1.1.

v1.3

2026-03-29

Xin Ruili

Modified the application experiment section

VII. Relevant Materials

7.1 Chip Datasheet

MLX90640 Manual.pdf 2.1 MB

7.2 Unique Icons for PCB Silk Screen

GraftSense: A Non-contact Infrared Image Sensor Module Based on MLX90640 Chip (Open Version)