close-circle
Close
0%
0%

Raspberry Pi Thermal Imaging

This project shows how to use the MLX90620 or MLX90621 16x4 Thermopile Array from the Raspberry Pi

Similar projects worth following
This project shows how to use the MLX90621 16x4 IR sensor array from the Raspberry Pi to add basic thermal imaging to your pi for under $100. It is a part of my ongoing project to build a general purpose electromagnetic scanner (prototype picture on left).

This Project is provided under the MIT license, enjoy ;-)

The MLX90620 and MLX 90621 are 16x4 remote temperature sensors. Both operate via I2C. The MLX sensors are very affordable and work well. The only drawback is that the sensors are designed for 'production line' so their 16x4 aspect ratio is not ideal. You can see in the picture of the thermo-data overlaying the camera image that we get a 'strip' of temperature data that runs either horizontally or vertically across the middle of the image depending on orientation.

Aside from this one drawback, they are pretty awesome little sensors. They will work from 3.3V but prefer a bit lower voltage. So it's prudent to connect a small rectifier diode in series with th positive power (a 1n4001 works nicely.) Other than that, wiring is the same as any I2C device-

MLX Raspberry Pi

  • Vcc -> Pin 1 (via 1n4001 diode to drop voltage)
  • SCL -> Pin 3
  • SDA -> Pin 5
  • Gnd -> Pin 9

You'll also need to make sure that i2c is enabled for your Raspberry Pi. (A pretty good guide on that is here- http://www.raspberrypi-spy.co.uk/2014/11/enabling-the-i2c-interface-on-the-raspberry-pi/)

Finally you'll need to enable the pi camera if you wish to run the 'mlxview' example that's included with the mlx90621 user space driver.

Once the device is physically installed and i2c is enabled verify that the SOC can see it by opening a terminal and running-

for Raspi - 'sudo i2cdetect -y 0'

for Raspi 2 - 'sudo i2cdetect -y 1'

(If that command is not found do 'sudo apt-get install i2c-tools'.)

Once you execute that command you'll see a grid of dashes with numbers where any i2c device is detected. The MLX has 2 i2c devices which collectively bind 9 i2c addresses - 50, 51, 52, 53, 54, 55, 56, 57 and 60

Addresses 50-57 and 60 below are the MLX90621. The other addresses are other i2c peripherals...

Once you can see the MLX90621 with 'i2cdetect' you can download and install the mlxd code from github.

To run the driver/daemon do- 'sudo mlxd &', if succesfull the thermopile data will now be available at - /var/run/mlx90620.sock

The mlxview.py application is an example app that grabs the thermopile data and attempts to superimpose it over the feed from the raspicam. It has a few python prerequisites. So if you want to run it first do -

'sudo apt-get install python-numpy python-scipy python-skimage'

(There may be other prerequisites I'm unaware of because I already had them installed. But those are the big ones...)

Here's a short video of the mlxview.py demo in action-



  • 1 × MLX90621 thermopile array
  • 1 × Raspberry Pi 2
  • 1 × Raspicam (and ribbon cable)
  • 1 × LCD display (HDMI or PiTFT)

View project log

Enjoy this project?

Share

Discussions

roerich wrote 06/26/2017 at 14:50 point

Hi, i have the problem that i can see the live picture from the picam but without overlaying the thermal image from the MLX90621.
i get
'pi@raspberrypi:~/mlxd $ python mlxview.py
/usr/lib/python2.7/dist-packages/skimage/util/dtype.py:107: UserWarning: Possible precision loss when converting from float64 to uint8
  "%s to %s" % (dtypeobj_in, dtypeobj))
^CTraceback (most recent call last):
  File "mlxview.py", line 90, in 
    fifo = open('/var/run/mlx90621.sock', 'r')
KeyboardInterrupt' 
then.
Can anybody help me please?

  Are you sure? yes | no

kadmomi1 wrote 05/05/2017 at 09:01 point

Hello charles, with sudo ./mlxd

OK, MLX9062x init
Ta = 22.79146767
C 73.02464180 F
I tried your solution
Mlxd is the driver daemon.
 : 'Sudo / full_path / to / mlxd &'
I get command not found
But I do not know what's wrong. Any suggestion?

I'm using google translate    

Thank you   

  Are you sure? yes | no

svtechie wrote 03/02/2017 at 06:49 point

Update: Following does not work

Before I fork and commit: I found latest code at https://github.com/terickson/mlxd/tree/56839dcf746b5fe0a5db7b51ae233075ecad1e3d. Please see if that works for you first.

I have checked in fixes at https://github.com/svtechie/mlxd

  Are you sure? yes | no

svtechie wrote 03/02/2017 at 06:44 point

Update: Code is available at https://github.com/svtechie/mlxd

To all:  If you are seeing Ta =  nan C  nan F, there is bug in the code. I have fixed this bug. I'll update the code at GitHub by 6th March 2017. 

  Are you sure? yes | no

svtechie wrote 03/01/2017 at 15:46 point

Hey Charles, I'm seeing exactly the same issue as John. I have tried to debug it but not sure what's wrong. Any suggestion? 

Thanks

  Are you sure? yes | no

John Lauer wrote 01/22/2017 at 07:35 point

I'm using an MLX90621 and I can't seem to get this to work. I get detection of the MLX90621, but when running mlxd I get the init, but no temp. Seems this is what a lot of folks are seeing as well. Any thoughts?

pi@raspberrypi:~ $ sudo i2cdetect -y 1

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 51 52 53 54 55 56 57 -- -- -- -- -- -- -- -- 
60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

But then getting...

pi@raspberrypi:~/mlxd $ sudo ./mlxd 

OK, MLX90620 init
Ta =  nan C  nan F

  Are you sure? yes | no

svtechie wrote 03/01/2017 at 15:44 point

John, I am seeing same issue. Were you able to resolve it?

  Are you sure? yes | no

svtechie wrote 03/02/2017 at 06:45 point

John, I have fixed the issue on my end. Going through remaining code. 

  Are you sure? yes | no

John Lauer wrote 01/22/2017 at 06:58 point

Your pins are reversed in your main description above. It caught me up for an hour.

SCL -> Pin 3
SDA -> Pin 5

Should be

SCL -> Pin 5
SDA -> Pin 3

  Are you sure? yes | no

Kenneth Tang wrote 01/13/2017 at 13:23 point

everything fine also but i also get the message: "Ta = nan C nan F", anyone has the solution?

  Are you sure? yes | no

svtechie wrote 03/01/2017 at 15:46 point

Hey Kenneth, were you able to resolve this issue? 

  Are you sure? yes | no

svtechie wrote 03/02/2017 at 06:46 point

I have fixed the issue on my end. Going through remaining code. Will update!

  Are you sure? yes | no

Patrick wrote 10/03/2016 at 18:07 point

Quick question.   Do you think it is possible to work with multiple MLX90621 sensors on the Raspberry PI?   Possibly leverage 4 sensors into the mix, rather than a single sensor?

  Are you sure? yes | no

Alpha Charlie wrote 10/12/2016 at 16:38 point

The Raspberry Pi has a second I2C bus (GPIO 28, 29) and in theory, you can have one per bus. (Note that I haven't tried it.) 

  Are you sure? yes | no

adarsh.ambati1 wrote 10/03/2016 at 13:47 point

Also, I can't access the thermopile data

  Are you sure? yes | no

Alpha Charlie wrote 10/12/2016 at 16:42 point

Sorry for the delay responding. Verify that you have I2C enabled, i2ctools installed, and that the device is visible when you run 'sudo i2cdetect -y 1'. (If you see all dashes in that grid, your sensor may be mis-wired.) See the I2c portion of this page - https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial

  Are you sure? yes | no

adarsh.ambati1 wrote 10/02/2016 at 19:19 point

Hi, I also have the Ta = nan C nan F error.

Cananybody help me?

  Are you sure? yes | no

Mark Dammer wrote 09/28/2016 at 17:39 point

Anybody knows where to get these sensors in the UK ?

  Are you sure? yes | no

yuting.wang wrote 09/28/2016 at 13:02 point

okay, I have solved the problem.

gcc -o mlxd mlxd.c -l bcm2835 -lm

sudo ./mlxd

  Are you sure? yes | no

yuting.wang wrote 09/27/2016 at 13:51 point

Hello, I also got the "command not found" problem and your suggestion to daihael did not work for me. Please help

  Are you sure? yes | no

msasikumar895 wrote 07/11/2016 at 10:59 point

Its working fine. But i have a problem with output while run the sudo mlxd & comment and its output is "Ta = nan C nan F". is this error or just an output

  Are you sure? yes | no

daihael wrote 05/09/2016 at 16:02 point

ok it worked ! thx 

now i have a problem with the output. i get the message: "Ta = nan C nan F"

I'm using a MLX90621. Does it really work with 621 ? maybe thats my problem ?

  Are you sure? yes | no

Alpha Charlie wrote 05/10/2016 at 05:59 point

No I'm using the 90621 in the video... 

if from a shell you execute the command 'sudo i2cdetect -y 1' does the output show devices at 50, 51, 52, 53, 54, 55, 56, 57 and 60? 

  Are you sure? yes | no

daihael wrote 05/10/2016 at 06:14 point

yes

  Are you sure? yes | no

msasikumar895 wrote 07/11/2016 at 11:15 point

Dear daihael,

Did you get any solution for this output message??

  Are you sure? yes | no

daihael wrote 05/04/2016 at 16:01 point

To run the driver/daemon do- 'sudo mlxd &', if succesfull the thermopile data will now be available at - /var/run/mlx90620.sock

I tried "sudo mlxd &" but  i get the response "sudo:mlxd: command not found"  ... heeeelp :)

is it just the command "sudo mlxd &" and what for is this command actually ?

  Are you sure? yes | no

Alpha Charlie wrote 05/07/2016 at 20:35 point

mlxd is the driver daemon. It needs to run as root (hence the 'sudo' at the front...) It sounds like mlxd is not in your PATH or the current directory. Try the full path to the daemon. - i.e. : 'sudo /full_path/to/mlxd &'

  Are you sure? yes | no

Alpha Charlie wrote 07/22/2015 at 20:09 point

Sorry for the slow reply. Sounds like your issues are hardware related. First make sure you are only supplying the MLX with ~2.7V by placing an 1n4001 diode in series with the power supply... Next double check your SCL/SDA lines. (If one is grounded out then ALL of the addresses will show as active in i2cdetect... If they are reversed or not connected, then nothing will show up.) Also make sure you've got i2c enabled on your Pi both in raspi-config and in /boot/config.txt (and /etc/modules)

Once you have i2c working the daemon should (hopefully) be able to connect. 

Also double check against the datasheet to make sure it's wired correctly.

  Are you sure? yes | no

Liathano wrote 07/21/2015 at 07:09 point

Hi,

really good description.
but I have a problem. If I say "run in terminal" the terminal is open for 1 sec and then is closing. so I can't measure anything (but need it for my studies..) and don't have a mlx90620.sock

What can be the reason? any tips?

thanks

  Are you sure? yes | no

Liathano wrote 07/21/2015 at 07:35 point

the 2nd problem is, that when I write 'sudo i2cdetect -y 1'

it shows nothing for the mlx90621, but every line shows a number if i try the mlx90614 .... 
hope you can help me, I really need it.

  Are you sure? yes | no

Bob Hannent wrote 09/27/2016 at 13:01 point

open a terminal window using xterm or some other option in your OS?

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates