ESP32 Projects
Start a build
Markdown

MLX90640 for ESP32-S3

An ESP32 camera project for ESP32-S3 involving Touchscreen, SD card.

ESP32-S3ArduinoUnrated
Parts and source

Before you start

Check the exact Touchscreen, SD card configuration against the upstream wiring or parts list.

Upstream README

MLX90640 Thermography Camera for ESP32

Description

Program for thermal imaging camera with MLX90640 far-infrared thermal sensor for XIAO ESP32S3 and ESP32-2432S028R

Features

It comes with a graphical user interface to properly configure the MLX90640 for different scenarios.

Configuration Menu

  • Display frame rate: 1 FPS (min) / 16 FPS (max)
  • Resolution: 32 x 24 (min) / 256 x 192 (max)
  • Heat map mode: Rainbow / Inferno
  • Measurement range: Auto scaling / Manual adjustment.
  • Measurement features: Automatic min/max / a specified point.
  • Screen capture: Save 320 x 240 bitmap (24-bit) to SD card.
  • Video recording: Record 32 x 24 raw data continuously onto SD card.
  • File explorer: Display thumbnails / Play videos on SD card.
  • Offline video viewer: Offline video playback on PC
  • Touch screen: Calibration on the first launch / in the configuration menu.

Demo

File Explorer

File Explorer

MLX90640Viewer

MLX90640Viewer

Hardware Setup

For GPIO pin assignments, see pin_assign.h.

XIAO ESP32S3
Block Diagram

Block Diagram

Wiring

Wiring

Prototype

Prototype

ESP32-2432S028R (AKA Cheap Yellow Display)
Connecting MLX90640 to I2C

Connecting MLX90640 to I2C with ESP32-2432S028R-MLX90640

Li-Po Battery

Schematics

Prototype

Li-Po and Booster

I2C pull-up registers

with and without pull-up registers

Software Setup

Requirements
File Structure and Dependencies
MLX90640.ino
├─ pin_assign.h
├─ heatmap.h
├─ mlx.hpp
├─ gfx.hpp
│   │ <LovyanGFX.h>
│   ├─ boards
│   │   ├─ LGFX_CYD_2432S028R.hpp
│   │   └─ LGFX_XIAO_ESP32S3_ST7789.hpp
│   │ <TFT_eSPI.h>
│   ├─ User_Setup.h
│   └─ boards
│       ├─ Setup_CYD_2432S028R.h
│       ├─ Setup_XIAO_ESP32S3_ST7789.h
│       └─ XPT2046_ScreenPoint.h
├─ task.hpp
├─ touch.hpp
├─ sdcard.hpp
├─ filter.hpp
├─ interpolation.hpp
└─ widget.hpp
    ├─ draw.hpp
    │   └─ marker.h
    └─ widgets.hpp
        └─ widgets.h
Configuration
  1. Depending on the board type, define pinouts of the I2C for MLX90640 and SPI for LCD / touch screen / SD card in pin_assign.h.

  2. Configure each step in MLX90640.ino. Generally, there is no need to change the default values.

  • Step1: Debugging mode (default: false)
  • Step2: Operational specifications
    • ENA_INTERPOLATION (default: true)
    • ENA_MULTITASKING (default: true)
    • ENA_OUTWARD_CAMERA (true: Outward, false: Selfie)
  • Step3: GFX library
    • USE_LOVYAN_GFX (default: true, highly recommended)
      • USE_AUTODETECT (default: true, or manual settings)
    • USE_TFT_ESPI
      • User_Setup.h (definition required)
  • Step4: Flash memory
    • USE_PREFERENCES (default: false, true is recommended.)
  • Step5: Resolution
    For low performance MCUs. No modifications required.
Dual-Core / Multitask

It achieves parallel processing by utilizing multi-cores with FreeRTOS and double-buffering for thermal images.

Timing diagram

Touch Screen Calibration

The “Calibration Screen” will appear when you run the sketch for the first time after compile & uploading, or when you select to run calibration from the menu.

Calibration Screen

Calibration Screen


If USE_PREFERENCES is set to true, you can save the calibration results to flash, but when it's set to false, you need to open the serial monitor with 115200 bps before running the calibration and embed the displayed data into touch.hpp after calibration is completed.

Screen Transition

On the main screen, there are four areas that provide special functions.

  • Thermal image (area A)
    Displays the temperature measurement at the touched point.
  • Imformation area (area B)
    Touching this area cancles the temperature measurement point specified in area A.
  • Thermogram scale (area C)
    Go directly to the Thermograph settings screen.
  • Gear icon (area D)
    Long-pressing takes you directly to the Capture Mode settings screen.
Screen transitions

Screen transition

Refresh Rate vs Noise

The MLX90640 datasheet shows the relationship between noise and refresh rate.

MLX90640 noise vs refresh rate

To obtain an image with less noise, please lower the frame rate.

1 FPS vs 16 FPS

Known Issues

ESP32 core version

It has been observed that, with ESP32 core version 3.3.8 and later, the MLX90640 refresh rate and image rendering process become slower. In the worst-case scenario, it is not possible to achieve 16 FPS.

Execution results in 3.3.12

Therefore, the recommended ESP32 core versions are 3.0.5 through 3.3.7 (excluding 3.3.6).

Using TFT_eSPI

When TFT_eSPI is selected,

  • rendering will be slower than LovyanGFX on ESP32-2432S028R.
  • screenshots can not be saved correctly on XIAO_ESP32S3.
  • MLX90640Viewer
    The MLX90640Viewer is a tool that applies heatmaps and visualizes the output of the Melexis MLX90640 32x24 IR array, which is stored as continuous raw data in a file.

  • MLX90640 for Arduino UNO R4

Resouces