MLX90640 infrared (IR) sensor array

I²C Connection

Much like the AMG8833 the MLX90640 just needs a minimal I²C connection and can be addressed at 0x33.  I've powered it at 3v3 direct from an ESP32C3 which retreives the data from the sensor and sends if over Wifi for further analysis.

Unfortunately reading the pixel data from the MLX90640-ESF-BAA (110°C) or MLX90640-ESF-BAB (55°C) is a lot more complex than the AMG8833.

Using a Library, or not.

There are libraries that (seem) to correctly implement the complex calculations necessary to read and accurately calculate the data for the MLX90640, none of them are easy to use (or just integrate) with ESP-IDF, I tested on a PiZero and got an indication it might not necessary to run the complex calculations that are beyond my immediate understanding.

Not using a library

Ok, lets just read the data.  

Setup

There is a Control Regsiter at 0x800d described on page 17, I write mostly the defaults to it:

000 - reserved
1 - Chess Pattern
10 - 18 bit resolution
011 - 4Hz refresh (or a complete refresh twice a second)
000 - Subpage 0
0 - transfer data on each frame 
0 - reserved
1 - Subpage mode

Once the set up is done, it's an infinite loop to read the data and xmit the raw data to a TCP socket.

Read some parameters

Ta_Vbe and Ta_PTAT.   Ta_Vbe (ambient temperature compensation value) is used to calculate an "average" temperature to use as a "black" pixel... The average isn't calibrated and it doesn't match the real average, but per tests below it works as a point from which to calculate whether a pixel is warmer or cooler.

Wait for dataReady 

Wait until Status Register bit 4 (0x08) is true

Read RAM

0x0400 - 0x06FF (768 pixel data)

0x0700 - 0x073f (extra stuff that is very important, but can actually be discarded)

Do some calculations

Calibrating

I pointed the sensor at a constant temperature source and read the pixel data.  Assuming (reasonably) that they should all be the same I created a "calibration array" that stores an offset for each pixel to be used in the calcuations.

The animation at right shows the raw data compared to what it looks like using just the simple offset.

This solution produces data that is useable for human detection with much simpler software.

 

 

 

Datasheet

https://files.waveshare.com/upload/7/73/MLX90640-EN.pdf

Melexis Github

My quick attempt without the complex maths is in mlx90640.c and it was used to produce this sequence of me walking back and forth with an icepack.

Walking back and forth with an icepack

 

Important Registers

Control Regsiter at 0x800d - 16bit

Status Regsiter at 0x8000 - 16bit, but really only 1 bit matters, "new data is available in RAM"

RAM at 0x4000 - 768 pixels each 16 bits and some extraneuos data (you can ignore if you're in a hurry)