Qwiic IR Array (MLX90640) Hookup Guide

Pages
Contributors: Englandsaurus
Favorited Favorite 3

Introduction

The Melexis MLX90640 (110° and 55° FOV) contains a 32x24 array of thermopile sensors creating, in essence, a low resolution thermal imaging camera. As the images show, you can detect surface temperatures from many feet away with an accuracy of ±1.5°C (best case). We’ve packaged the MLX90640 on an easy to use Qwiic board with mounting holes and a smattering of decoupling caps.

SparkFun IR Array Breakout - 110 Degree FOV, MLX90640 (Qwiic)

SparkFun IR Array Breakout - 110 Degree FOV, MLX90640 (Qwiic)

SEN-14843
$74.95
6
SparkFun IR Array Breakout - 55 Degree FOV, MLX90640 (Qwiic)

SparkFun IR Array Breakout - 55 Degree FOV, MLX90640 (Qwiic)

SEN-14844
$74.95
4

In this guide, we'll go over how to connect your Qwiic IR Array with MLX90640 and get it communicating with Processing to produce a nice thermal image.

Required Materials

Not Uno Compatible: The MLX90640 requires complex calculations by the host platform. A regular Uno doesn't have enough RAM or flash to complete the complex computations required to turn the raw pixel data into temperature data. You will need a microcontroller with 20,000 bytes or more of RAM. We recommend a Teensy 3.1 or above. Make sure to grab headers if you get a headerless version of the Teensy.
Break Away Headers - Straight

Break Away Headers - Straight

PRT-00116
$1.75
20

Teensy 3.2

DEV-13736
68

Teensy 3.5 (Headers)

DEV-14056
1 Retired

Teensy 3.6 (Headers)

DEV-14058
7 Retired

We don't have any Qwiic shields available for Teensy, so you should snag yourself a breadboard and a breadboard friendly Qwiic cable if you haven't already to get the Teensy connected to the MLX90640.

Breadboard - Classic

Breadboard - Classic

PRT-00112
$10.95
19
Breadboard - Translucent Self-Adhesive (Clear)

Breadboard - Translucent Self-Adhesive (Clear)

PRT-09567
$5.50
15
Breadboard - Self-Adhesive (White)

Breadboard - Self-Adhesive (White)

PRT-12002
$5.50
48
Qwiic Cable - Breadboard Jumper (4-pin)

Qwiic Cable - Breadboard Jumper (4-pin)

PRT-14425
$1.50

Tools

Depending on your setup, you may need a soldering iron, solder, and general soldering accessories if you bought a headerless Teensy.

Solder Lead Free - 100-gram Spool

Solder Lead Free - 100-gram Spool

TOL-09325
$9.95
8

Weller WLC100 Soldering Station

TOL-14228
2 Retired

Suggested Reading

If you aren't familiar with the Qwiic system, we recommend reading here for an overview.

Qwiic Connect System
Qwiic Connect System

Since we'll also be using Processing in one of these demos, we'd recommend looking up the tutorial on hooking your Arduino up to Processing. We would also recommend taking a look at the following tutorials if you aren't familiar with them.

How to Solder: Through-Hole Soldering

This tutorial covers everything you need to know about through-hole soldering.

Connecting Arduino to Processing

Send serial data from Arduino to Processing and back - even at the same time!

I2C

An introduction to I2C, one of the main embedded communications protocols in use today.

Hardware Overview

First, let's check out some of the characteristics of the MLX90640 IR Array we're dealing with, so we know what to expect out of the board. Keep in mind that there are two options for the field of view 110°x75° and 55°x35°

CharacteristicRange
Operating Voltage3V-3.6V
Current Consumption~18 mA
Measurement Range-40 °C - 300°C
Resolution±1.5°C
Refresh Rate0.5Hz - 64 Hz
I2C Address0x33

Pins

The following table lists all of the MLX90640's pins and their functionality.

PinDescriptionDirection
GNDGroundIn
3.3VPowerIn
SDADataIn/Out
SCLClockIn

Optional Features

The MLX90640 IR Array has pull up resistors attached to the I2C bus; if multiple sensors are connected to the bus with the pull-up resistors enabled, the parallel equivalent resistance will create too strong of a pull-up for the bus to operate correctly. As a general rule of thumb, disable all but one pair of pull-up resistors if multiple devices are connected to the bus. If you need to disconnect the pull up resistors they can be removed by cutting the traces on the corresponding jumpers highlighted below.

I2C Pull Up Jumper

I2C Pull Up Jumper

The onboard LED (highlighted below) will light up when the board is powered, and the sensor (also highlighted below) should be left uncovered in your application.

Power LED

Power LED

Hardware Assembly

Since we don't have a Qwiic shield for the Teensy at this point in time, we'll need to connect our Qwiic Infrared Array through the breadboard compatible Qwiic cable. Check out the following table if you're unsure of how to connect your Qwiic cable. The Teensy 3.5 pinout is available here. For more pin assigments, refer to the Teensy's reference page.

ColorFunctionPin
BlackGroundAny GND pin
RedPower (3.3V)Any 3.3V pin
YellowClock19
BlueData18

Once you have your cable hooked up to the breadboard, go ahead and plug it into your MLX90640 IR Array and you'll be ready to go.

MLX90640 Plugged into Breadboard

MLX90640 Plugged into Breadboard

Example Code

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE.

Teensyduino Add-On

If you haven't used Teensy before, you'll probably need to download and install the extension for the Arduino IDE called Teensyduino, located here.

Library

Melexis has written a library to control the Qwiic IR Array with MLX90640. You can obtain these libraries by clicking the below button, which also includes the SparkFun written example sketches from the GitHub repository. Just makes sure the associated files are in the same path when opening each example.

Example 1 - Basic Readings

Once you've downloaded the example sketches and library, go ahead and open the first example under SparkFun_MLX90640_Arduino_Example-master > Firmware > Example1_BasicReadings > Example1_BasicReadings. To initialize the sensor, we first attempt to talk to the MLX90640 with the isConnected() function. Looking closer at our setup() loop reveals that we extract a set of paramaters from the MLX using MLX90640_DumpEE and MLX90640_ExtractParamaters. This only needs to be done once in the setup() loop before the board is ready to use, the code is shown below.

language:c
void setup()
{
  Wire.begin();
  Wire.setClock(400000); //Increase I2C clock speed to 400kHz

  Serial.begin(9600);
  while (!Serial); //Wait for user to open terminal
  Serial.println("MLX90640 IR Array Example");

  if (isConnected() == false)
  {
    Serial.println("MLX90640 not detected at default I2C addres. Please check wiring. Freezing.");
    while (1);
  }
  Serial.println("MLX90640 online!");

  //Get device parameters - We only have to do this once
  int status;
  uint16_t eeMLX90640[832];
  status = MLX90640_DumpEE(MLX90640_address, eeMLX90640);
  if (status != 0)
    Serial.println("Failed to load system parameters");

  status = MLX90640_ExtractParameters(eeMLX90640, &mlx90640);
  if (status != 0)
    Serial.println("Parameter extraction failed");

  //Once params are extracted, we can release eeMLX90640 array
}

Once you've selected your board and serial port, upload the sketch to your Teensy. Then open the serial monitor set at 115200 baud. The output should look something like the below image, with the temperature values of each pixel being displayed in °C.

Example 1 Output

Example 1 Output

Example 2 - Output To Processing

Note: Processing is a software that enables visual representation of data, among other things. If you've never dealt with Processing before, we recommend you also check out the Arduino to Processing tutorial. Follow the below button to go ahead and download and install Processing.

Download Processing IDE

This next example involves the Processing IDE. Processing listens for serial data, so we'll need to get our Arduino producing serial data that makes sense to Processing. To pull up the next example, go to SparkFun_MLX90640_Arduino_Example-master > Firmware > Example2_OutputToProcessing > Example2_OutputToProcessing to open the example sketch. This sketch simply prints a comma separated list of our temperatures over serial for Processing to listen to.

Once this sketch is uploaded, we need to tell Processing how to turn this data into a visualization. The Processing sketch to do this is located in the same folder as Example 2. So go to the sketch folder to open the MLXHeatCam file in Processing. Attempting to run the sketch will show us available serial ports in the debug window.

COM Port Selection

Identify which serial port your Teensy is on. For instance, my Teensy is on COM6, which corresponds to [1] in the above image, so I will need to change 0 to 1 in the following line to ensure Processing is listening in the right location.

language:c
myPort = new Serial(this, Serial.list()[0], 115200);

Once I've done this, we should be able to run the Processing sketch and it will give us a nice visualization of the pixels on our Qwiic IR Array with MLX90640. Move your face or hand in front of the sensor and see what it looks like on the screen. The output should look similar to the image below. Note that the camera can only hit about 4 Hz due to the data rate over I2C. The hypothetical refresh rate of the MLX90640 is 64 Hz, but unless you have a microcontroller capable of a much faster I2C rate, you won't be hitting framerates anywhere near that.

IR Camera

IR Camera Display

Resources and Going Further

Now that you've successfully got your Qwiic IR Array with MLX90640 up and running, it's time to incorporate it into your own project!

For more information, check out the resources below:

Need some inspiration for your next project? Check out some of these related tutorials:

FLIR Lepton Hookup Guide

See the invisible world of infrared radiation using the FLIR Dev Kit and Raspberry Pi.

MLX90614 IR Thermometer Hookup Guide

How to use the MLX90614 or our SparkFun IR Thermometer Evaluation Board to take temperatures remotely, over short distances.

Qwiic GRID-Eye Infrared Array (AMG88xx) Hookup Guide

The Panasonic GRID-Eye (AMG88xx) 8x8 thermopile array serves as a functional low-resolution infrared camera. This means you have a square array of 64 pixels each capable of independent temperature detection. It’s like having thermal camera (or Predator’s vision), just in really low resolution.