Thermal Camera


I got the MLX90640 thermal camera working on a Pi today. On a pi zero also!

Example software is a bit rough and ready - I had to edit away a couple of errors - and the camera needs powering off when changing modes. I guess the software needs to reset state better. A good starting point I think.

I had a problem with using alongside a pijuice and display. They must conflict somehow. A clean install of Raspbian without the other hats sorted it.




It’s a very, very finickity camera! I’m hoping to get software support to the point where it’s more widely available to beginners but it’s been an uphill struggle.

The big issue currently is that it uses the bcm2836s libraries i2c access which, irc, accesses the i2c registers directly and causes some serious problems with the kernel level i2c drivers. The two appear to be mutually exclusive, which is a pain :(


I’m a beginner and got it working, so you must be doing something right! Any pointers in how to measure temp or which file I use to change the output size would be awesome…


In, for example, fbuf.cpp (I really need to pick better filenames for these examples!) these are the lines that display the temperature data on the screen:

At this point the value set to val is the temperature in degrees C of that particular pixel.

If you want to get the temperature at the centre of the sensor you would wait for y to be 11 or 12 and x to be 15 or 16 and measure that pixel, or perhaps take the average of these four.

If you want to measure at a specific point you could reverse engineer the loop into a function to get a pixel at a particular x/y:

float  getPixelAt(int x, int y, float *pixelData){
    return pixelData[32 * (23-y) + x];

(This may not work because, and this may come as a surprise to the untrained eye, I suck at C/C++)

As for displaying this value, that’s another matter. With the framebuffer value I’m doing a quick and dirty push into /dev/fb0 which is a truly horrible way to draw graphics but gets the job done. There’s no easy way to draw a text string without pixelling it in from a pixel font map. That said you only need the characters 0-9, “.” and “°C”.

fbuf.c and interp.c (horrible, horrible filenames) both have an IMAGE_SCALE value which handles basic upscaling by redrawing the pixels as IMAGE_SCALE pixel wide blocks.

interp.c additionally has OUTPUT_W and OUTPUT_H which determine how much cubic interpolation should be applied to the image before it is draw.

These values can slow down output immensely, though, so don’t drive them too far! You can also use fbset on the Terminal to reduce your framebuffer resolution so that smaller images are stretched across your screen at no additional processing cost.


This would be really useful if I could get something to continually return the ‘temperature’ of the pixels! Will have a play!


did someone tried to use this camera with OpenCV? I want to buy such a camera, the 110° FOV as soon it becomes available. My goal is to track persons movement direction and counting.


I did wonder if using something like v4l2loopback to create a virtual v4l2 device would make it accessible to opencv, plus other standard camera applications and tools.


not a bad ideea at all, but first we need to get the device itself, i observed that is not on stock anymore, i need the 110° FOV version and no one knows when it will be available again