# Adafruit MLX90640 IR Thermal Camera

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/087/280/medium800/adafruit_products_MLX90640_110_top.jpg?1579647441)

You can now add affordable heat-vision to your project with an Adafruit MLX90640 Thermal Camera Breakout. This sensor contains a 24x32 array of IR thermal sensors. When connected to your microcontroller (or Raspberry Pi) it will return an array of 768 individual infrared temperature readings over I2C. It's like those fancy thermal cameras, but compact and simple enough for easy integration.

![](https://cdn-learn.adafruit.com/assets/assets/000/087/281/medium800/adafruit_products_MLX90640_55_top_angle.jpg?1579647452)

There are two versions: one with a [wider&nbsp; **110°x70° field of view**](https://www.adafruit.com/product/4469) and one with a [narrower **55°x35° field of view**](https://www.adafruit.com/product/4407).

![](https://cdn-learn.adafruit.com/assets/assets/000/087/282/medium800/adafruit_products_MLX90640_110_top_angle.jpg?1579647463)

This part will measure temperatures ranging from&nbsp; **-40°C to 300°C&nbsp;** with an accuracy of +- 2°C (in the 0-100°C range). With a maximum frame rate of 16 Hz (the theoretical limit is 32Hz but we were not able to practically achieve it), It's perfect for creating your own human detector or mini thermal camera. We have code for using this sensor on an Arduino or compatible (the sensor communicates over I2C) or on a Raspberry Pi with Python. If using an Arduino-compatible, you'll need a processor with at least 20KB RAM - a SAMD21 (M0) or SAMD51 (M4) chipset will do nicely. On the Pi, you can even perform interpolation processing with help from the SciPy python library and get some pretty nice results!

![](https://cdn-learn.adafruit.com/assets/assets/000/087/283/medium800/adafruit_products_MLX90640_55_top_header.jpg?1579647482)

This sensor reads the data twice per frame, in a checker-board pattern, so it's normal to see a checker-board dither effect when moving the sensor around - the effect isn't noticeable when things move slowly.

![](https://cdn-learn.adafruit.com/assets/assets/000/087/284/medium800/adafruit_products_MLX90640_110_back.jpg?1579647493)

To make it easy to use, we hand-soldered it on a breakout board with a 3.3V regulator and level shifting. So you can use it with any 3V or 5V microcontroller or computer. We've even included&nbsp;[SparkFun qwiic](https://www.sparkfun.com/qwiic)&nbsp;compatible**&nbsp;[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt)**&nbsp;connectors for the I2C bus so&nbsp; **you don't even need to solder!** &nbsp;Just plug-n-play with any of our STEMMA QT (JST SH) cables.

Even better - We've done all the hard work here, with example code and supporting software libraries to get you up in running in just&nbsp;[a few lines of Arduino](https://github.com/adafruit/Adafruit_MLX90640)&nbsp;or&nbsp;[Python code](https://github.com/adafruit/Adafruit_CircuitPython_MLX90640).

# Adafruit MLX90640 IR Thermal Camera

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/087/351/medium800/adafruit_products_MLX90640_110_vs_55.jpg?1579733757)

There is no difference between the breakout for the 55°x35° field of view and the 110°x70° field of view thermal cameras. There is also no difference in the code used with either thermal camera.&nbsp; **The only difference is the length of the lens.** The only way to tell which thermal camera breakout you have is to identify the length of the lens. The longer lens, shown above on the left, is on the 55°x35° field of view thermal camera and is approximately 11.25mm long. The shorter lens, shown above on the right, is on the 110°x70° field of view thermal camera and is approximately 5.7mm long.

![](https://cdn-learn.adafruit.com/assets/assets/000/087/352/medium800/adafruit_products_MLX90640_110_top_pinouts.jpg?1579733813)

## Power Pins

- **VIN** - this is the power pin. Since the sensor chip uses 3 VDC, we have included a voltage regulator on board that will take 3-5VDC and safely convert it down. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V
- **3V** &nbsp;- this is the 3.3V output from the voltage regulator, you can grab up to 100mA from this if you like
- **GND** - common ground for power and logic

## I2C Logic Pins

- **SCL** - I2C clock pin, connect to your microcontroller I2C clock line. This pin is level shifted so you can use 3-5V logic, and there's a **4.7K pullup** on this pin.
- **SDA** - I2C data pin, connect to your microcontroller I2C data line. This pin is level shifted so you can use 3-5V logic, and there's a **4.7K pullup** on this pin.

![](https://cdn-learn.adafruit.com/assets/assets/000/087/353/medium800/adafruit_products_MLX90640_55_back_pinouts.jpg?1579733930)

## STEMMA Connectors

- **[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt)&nbsp;-** These connectors on the back of this breakout allow you to connect to dev boards with **STEMMA QT** connectors or to other things with&nbsp;[various associated accessories](https://www.adafruit.com/?q=JST%20SH%204)

# Adafruit MLX90640 IR Thermal Camera

## Arduino Libraries

You're going to need to install a few libraries to use this sensor. These are all in the Arduino Library Manager, so they're quite easy to install.

## Library Installation

You're going to need to install a few libraries to use this sensor. These are all in the Arduino Library Manager, so they're quite easy to install.

You can install the **Adafruit MLX90640 Library** for Arduino using the Library Manager in the Arduino IDE.

![](https://cdn-learn.adafruit.com/assets/assets/000/087/464/medium800/adafruit_products_MLX90640_arduino_manage_libraries.png?1579886050)

Click the&nbsp; **Manage Libraries...** menu item, search for **Adafruit MLX90640** ,&nbsp;and select the&nbsp; **Adafruit MLX90640** library:

![](https://cdn-learn.adafruit.com/assets/assets/000/087/465/medium800/adafruit_products_MLX90640_arduino_MLX_lib_install.png?1579886156)

Then follow the same process for the&nbsp; **Adafruit BusIO** &nbsp;library.

![](https://cdn-learn.adafruit.com/assets/assets/000/087/466/medium800/adafruit_products_Arduino_BusIO_Lib_Install.png?1579886218)

In the next page, you'll install all the libraries used for Arcada, which is another dependency.

# Adafruit MLX90640 IR Thermal Camera

## Arcada Libraries

OK now that you have Arduino IDE set up, drivers installed if necessary and you've practiced uploading code, you can start installing all the Libraries we'll be using to program it.

**There's a lot of libraries!**

# Install Libraries

Open up the library manager...

![](https://cdn-learn.adafruit.com/assets/assets/000/073/288/medium800/circuitpython_managelib.png?1552873775)

And install the following libraries:

## Adafruit Arcada

This library generalizes the hardware for you so you can read the joystick, draw to the display, read files, etc. without having to worry about the underlying methods

![](https://cdn-learn.adafruit.com/assets/assets/000/075/990/medium800/adafruit_products_image.png?1558676193)

Warning: 

## If you aren't running Arduino IDE 1.8.10 or later, you'll need to install _all_ of the following!

&nbsp;

## Adafruit NeoPixel

This will let you light up the status LEDs on the front/back

![](https://cdn-learn.adafruit.com/assets/assets/000/073/289/medium800/circuitpython_adafruit_products_image.png?1552873804)

# Adafruit FreeTouch

This is the open source version of QTouch for SAMD21 boards

![](https://cdn-learn.adafruit.com/assets/assets/000/081/517/medium800/adafruit_products_image.png?1569566140)

# Adafruit Touchscreen

Used by Adafruit Arcada for touchscreen input (required even if your Arcada board does not have a touchscreen)

![](https://cdn-learn.adafruit.com/assets/assets/000/076/086/medium800/adafruit_products_image.png?1558904134)

## Adafruit SPIFlash

This will let you read/write to the onboard FLASH memory with super-fast QSPI support

![](https://cdn-learn.adafruit.com/assets/assets/000/073/292/medium800/circuitpython_adafruit_products_SPIFlash_lib.jpg?1552873977)

## Adafruit Zero DMA

This is used by the Graphics Library if you choose to use DMA

![](https://cdn-learn.adafruit.com/assets/assets/000/073/291/medium800/circuitpython_adafruit_products_zeroDMA_lib.jpg?1552873858)

## Adafruit GFX

This is the graphics library used to draw to the screen

![](https://cdn-learn.adafruit.com/assets/assets/000/073/293/medium800/circuitpython_image.png?1552874131)

If using an older (pre-1.8.10) Arduino IDE, locate and install **Adafruit\_BusIO** (newer versions do this one automatically).

## Adafruit ST7735

The display on the PyBadge/PyGamer & other Arcada boards

![](https://cdn-learn.adafruit.com/assets/assets/000/075/987/medium800/adafruit_products_image.png?1558675936)

## Adafruit ILI9341

The display on the PyPortal & other Arcada boards

![](https://cdn-learn.adafruit.com/assets/assets/000/076/110/medium800/adafruit_products_image.png?1558926181)

## Adafruit LIS3DH

For reading the accelerometer data, required even if one is not on the board

![](https://cdn-learn.adafruit.com/assets/assets/000/075/988/medium800/adafruit_products_image.png?1558676020)

## Adafruit Sensor

Needed by the LIS3DH Library, required even if one is not on the board

![](https://cdn-learn.adafruit.com/assets/assets/000/075/989/medium800/adafruit_products_image.png?1558676086)

# Adafruit ImageReader

For reading bitmaps from SPI Flash or SD and displaying

![](https://cdn-learn.adafruit.com/assets/assets/000/073/298/medium800/circuitpython_image.png?1552874434)

# ArduinoJson

We use this library to read and write configuration files

![](https://cdn-learn.adafruit.com/assets/assets/000/076/085/medium800/adafruit_products_image.png?1558840996)

# Adafruit ZeroTimer

We use this library to easily set timers and callbacks on the SAMD processors

![](https://cdn-learn.adafruit.com/assets/assets/000/076/181/medium800/adafruit_products_image.png?1559138259)

# Adafruit TinyUSB

This lets us do cool stuff with USB like show up as a Keyboard or Disk Drive

![](https://cdn-learn.adafruit.com/assets/assets/000/078/489/medium800/adafruit_products_image.png?1563856960)

# Adafruit WavePlayer

Helps us play .WAV sound files.

![](https://cdn-learn.adafruit.com/assets/assets/000/083/175/medium800/adafruit_products_waveplayer-install.png?1572322178)

## SdFat (Adafruit Fork)

The Adafruit fork of the really excellent SD card library that gives a lot more capability than the default SD library

![](https://cdn-learn.adafruit.com/assets/assets/000/083/166/medium800/adafruit_products_image.png?1572315153)

# Audio - Adafruit Fork

Our fork of the Audio library provides a toolkit for building streaming audio projects.

![](https://cdn-learn.adafruit.com/assets/assets/000/087/841/medium800/adafruit_products_audio.png?1580397029)

# Adafruit MLX90640 IR Thermal Camera

## Arduino Wiring and Example

## I2C Wiring

Use this wiring to connect via I2C interface.

- &nbsp;Connect&nbsp;**board VIN (red wire)** to&nbsp; **Arduino**  **5V** &nbsp;if you are running a **5V** board Arduino (Uno, etc.).&nbsp;If your board is **3V,** connect to that instead.
- Connect **board** **GND (black wire)&nbsp;**to&nbsp; **Arduino**  **GND**
- Connect **board** **SCL (yellow wire)&nbsp;**to&nbsp; **Arduino**  **SCL**
- Connect **board** **SDA (blue wire)&nbsp;**to&nbsp; **Arduino**  **SDA**

![adafruit_products_MLX90640_Metro_Arduino_STEMMA_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/092/385/medium640/adafruit_products_MLX90640_Metro_Arduino_STEMMA_bb.png?1592497506)

The final results should resemble the illustration above, showing an Adafruit Metro development board.

## Load Example

Open up&nbsp; **File -\> Examples -\> Adafruit MLX90640**  **-\> MLX90640\_simpletest** and upload to your Arduino wired up to the sensor.

Once you upload the code and open the Serial Monitor ( **Tools-\>Serial Monitor** ) at **115200** baud, you will see an ASCII representation of the thermal camera printed. You should see something similar to this:

![](https://cdn-learn.adafruit.com/assets/assets/000/092/383/medium800/adafruit_products_MLX90640_Arduino_simpletest_serial_output_ASCII.png?1592496127)

Point the thermal camera at objects of differing temperatures to see the ASCII image change!

You also have the option to see the temperatures printed out in a grid. Change the lines below `// uncomment *one* of the below` to comment out the `ASCIIART` line and uncomment the `TEMPERATURES` line so that they match below:

```cpp
// uncomment *one* of the below
#define PRINT_TEMPERATURES
//#define PRINT_ASCIIART
```

Upload the code and open the Serial Monitor ( **Tools-\>Serial Monitor** ) at **115200** baud, and you will see a grid of temperatures in Celsius printed. To fit the entire grid, you may need to resize the serial monitor window.

![](https://cdn-learn.adafruit.com/assets/assets/000/092/384/medium800/adafruit_products_MLX90640_Arduino_simpletest_serial_output_temps.png?1592496237)

Point the thermal camera at objects of differing temperatures to see the printed temperatures change.

https://github.com/adafruit/Adafruit_MLX90640/blob/master/examples/MLX90640_simpletest/MLX90640_simpletest.ino

# Adafruit MLX90640 IR Thermal Camera

## Arduino Docs

# Adafruit MLX90640 IR Thermal Camera

## Arduino PyBadge and PyGamer Thermal Camera

The PyBadge and PyGamer boards both have displays built in, as well as STEMMA I2C connectors. The MLX90640 comes with STEMMA QT/QWIIC connectors to allow for attaching the board easily to projects with no soldering required. Adafruit sells a [STEMMA to STEMMA QT cable](https://www.adafruit.com/product/4424) that allows you to plug this breakout into the STEMMA connector found on a number of Adafruit microcontroller boards, including PyBadge and PyGamer. The following example uses the PyBadge or PyGamer and the MLX90640 to create a super easy-to-assemble thermal camera with a display!

Start by following your board's guide on installing Arduino IDE, and support for the board you have. Then, follow the instructions on [the Arduino page in this guide](https://learn.adafruit.com/adafruit-mlx90640-ir-thermal-camera/arduino) to install the base libraries needed for this breakout. [Finally, install the Adafruit Arcada libraries](https://learn.adafruit.com/adafruit-pybadge/arcada-libraries) (there's a _lot_ of em!).

## Loading the Example
Go to **File \> Examples \> Adafruit MLS90640 \> MLX90640\_arcadacam** to open the ArcadaCam Arduino thermal camera example, and then load it onto your PyBadge or PyGamer.

![adafruit_products_MLX90640_arduino_examples.png](https://cdn-learn.adafruit.com/assets/assets/000/087/499/medium640/adafruit_products_MLX90640_arduino_examples.png?1579900942)

![adafruit_products_MLX90640_arduino_load_arcadacam.png](https://cdn-learn.adafruit.com/assets/assets/000/087/500/medium640/adafruit_products_MLX90640_arduino_load_arcadacam.png?1579900959)

Now point the thermal camera at various objects to see a heat map displayed on your board!

![](https://cdn-learn.adafruit.com/assets/assets/000/087/518/medium800thumb/adafruit_products_MLX90640_gif_800.jpg?1579910145)

https://github.com/adafruit/Adafruit_MLX90640/blob/master/examples/MLX90640_arcadaCam/MLX90640_arcadaCam.ino

# Adafruit MLX90640 IR Thermal Camera

## Arduino Feather and LCD Thermal Camera

![](https://cdn-learn.adafruit.com/assets/assets/000/140/704/medium800/adafruit_products_20251021_114853.jpg?1761076500)

Here is a version of the thermal camera in Arduino with a Feather and discrete LCD display as an alternate to the Arcada-based devices like PyPortal and PyGamer.&nbsp;

This version uses an Adafruit Feather M0 Express and an ILI9341-based display in addition to the MLX90640 thermal sensor. The display connects over an SPI interface and the sensor over an I2C interface.

## Parts
Featured
### Adafruit Feather M0 Express

[Adafruit Feather M0 Express](https://www.adafruit.com/product/3403)
At the Feather M0's heart is an ATSAMD21G18 ARM Cortex M0+ processor, clocked at 48 MHz and at 3.3V logic, the same one used in the new&nbsp;[Arduino Zero](https://www.adafruit.com/products/2843). This chip has a whopping 256K of FLASH (8x more than the Atmega328 or 32u4) and...

In Stock
[Buy Now](https://www.adafruit.com/product/3403)
[Related Guides to the Product](https://learn.adafruit.com/products/3403/guides)
![Angled shot of rectangular microcontroller.](https://cdn-shop.adafruit.com/640x480/3403-04.jpg)

Featured
### Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket

[Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket](https://www.adafruit.com/product/2478)
Add some jazz & pizzazz to your project with a color touchscreen LCD. This TFT display is 2.4" diagonal with a bright (4 white-LED) backlight and it's colorful! 240x320 pixels with individual RGB pixel control, this has way more resolution than a black and white 128x64...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2478)
[Related Guides to the Product](https://learn.adafruit.com/products/2478/guides)
![TFT breakout wired to arduino, hand doodling of a flower and a sun using touchscreen](https://cdn-shop.adafruit.com/640x480/2478-07.jpg)

Featured
### Adafruit MLX90640 IR Thermal Camera Breakout

[Adafruit MLX90640 IR Thermal Camera Breakout](https://www.adafruit.com/product/4407)
You can now add affordable heat-vision to your project and with an Adafruit MLX90640 Thermal Camera Breakout. This sensor contains a 24x32 array of IR thermal sensors. When connected to your microcontroller (or Raspberry Pi) it will return an array of 768 individual infrared temperature...

In Stock
[Buy Now](https://www.adafruit.com/product/4407)
[Related Guides to the Product](https://learn.adafruit.com/products/4407/guides)
![Angled shot of a Adafruit MLX90640 IR Thermal Camera Breakout.](https://cdn-shop.adafruit.com/640x480/4407-05.jpg)

The above sensor has a 55 degree field of view. for a 110 degree field of view, use [this version](https://www.adafruit.com/product/4469).

Featured
### Full Sized Premium Breadboard - 830 Tie Points

[Full Sized Premium Breadboard - 830 Tie Points](https://www.adafruit.com/product/239)
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip in the middle and two power rails on both sides. You can pull the power rails off easily to make the...

In Stock
[Buy Now](https://www.adafruit.com/product/239)
[Related Guides to the Product](https://learn.adafruit.com/products/239/guides)
![Angled shot of full sized breadboard.](https://cdn-shop.adafruit.com/640x480/239-03.jpg)

Featured
### STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable

[STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable](https://www.adafruit.com/product/4209)
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium Dupont male headers on the other. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert...

In Stock
[Buy Now](https://www.adafruit.com/product/4209)
[Related Guides to the Product](https://learn.adafruit.com/products/4209/guides)
![Angled Shot of the STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable.](https://cdn-shop.adafruit.com/640x480/4209-05.jpg)

![](https://cdn-learn.adafruit.com/assets/assets/000/140/707/medium800/adafruit_products_Thermal_camera_bb.jpg?1761076999)

## Wiring

See the Fritzing diagram above. The following connections are needed:

**From the Feather to the display:**

- **Feather 3V** pin to **display Vin**
- **Feather GND** pin to **display GND**
- **Feather SCK** to **display CLK**
- **Feather MO** to **display MOSI**
- **Feather Pin 10** to **display D/C**
- **Feather Pin 9** to **display CS**
- **Feather or display 3V output (never 5V!) to IM3, IM2, and IM1 (but not IM0!) pins. &nbsp;**This configures the breakout to use its SPI interface. &nbsp;See the breakout guide for [details on soldering closed these connections to make the SPI interface the default](https://learn.adafruit.com/adafruit-2-dot-8-color-tft-touchscreen-breakout-v2/spi-wiring#spi-mode-jumpers).

**Connections from the Feather to the sensor:**

The sensor has STEMMA QT connectors. This Feather does not. A cable like [STEMMA QT to male pins](https://www.adafruit.com/product/4209) may be used if a Stemma connection is desired.

- **Feather 3V** to **sensor VIN**
- **Feather GND** to **sensor GND**
- **Feather SCL** to **sensor SCL**
- **Feather SDA** to **sensor SDA**

**NOTE: The MLX90640 board in Fritzing is UPSIDE DOWN from the usual placement with the camera sensor up.** Use the connection pins noted to get the wiring correct.

For the STEMMA QT cable:

- Red - 3.3VDC Power
- Black - Ground
- Blue - I2C SDA Data
- Yellow - I2C SCL Clock

![](https://cdn-learn.adafruit.com/assets/assets/000/140/731/medium800/adafruit_products_Untitled.jpg?1761142149 A close up of the top of the MLX90640 showing the connections. Note the pin connections if not using a STEMMA QT cable.)

## Required Libraries

This project uses the **Adafruit MLX90640 library** , the **Adafruit ILI9341 library** , and the **Adafruit GFX library**. Be sure to install all library dependencies and ensure all libraries are at their latest versions. The process is the same as the [Arduino Libraries page](https://learn.adafruit.com/adafruit-mlx90640-ir-thermal-camera/arduino) in this guide.

## Code

Use the Download button to get the code for the project.

https://github.com/adafruit/Adafruit_MLX90640/blob/master/examples/MLX90640_ILI9341/Thermal.ino

![](https://cdn-learn.adafruit.com/assets/assets/000/140/711/medium800thumb/adafruit_products_ezgif-811d7f28d513bf_squished.jpg?1761081624)

You can change the line `tft.setRotation(1);` to one of the following values if you need to orient your display differently in relation to the sensor:

```cpp
tft.setRotation(0);  // Normal orientation
tft.setRotation(1);  // Rotate 90° clockwise
tft.setRotation(2);  // Upside down
tft.setRotation(3);  // Rotate 270° clockwise
```

# Adafruit MLX90640 IR Thermal Camera

## Python & CircuitPython

It's easy to use the MLX90640 sensor with Python and CircuitPython, and the [Adafruit CircuitPython MLX90640](https://github.com/adafruit/Adafruit_CircuitPython_MLX90640) module. This module allows you to easily write Python code that reads temperature using the thermal camera.

You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python [thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

## CircuitPython Microcontroller Wiring

First wire up a MLX90640 to your board for an I2C connection, exactly&nbsp; as shown below.&nbsp; Here's an example of wiring a Feather M4 to the sensor with I2C:

- **Board 3V** &nbsp;to&nbsp;**sensor VIN (red wire)**
- **Board GND** &nbsp;to&nbsp;**sensor GND (black wire)**
- **Board SCL** &nbsp;to&nbsp;**sensor SCL (yellow wire)**
- **Board SDA** &nbsp;to&nbsp;**sensor SDA (blue wire)**

![adafruit_products_MLX90640_Feather_M4_STEMMA_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/087/385/medium640/adafruit_products_MLX90640_Feather_M4_STEMMA_bb.png?1579806338)

![adafruit_products_MLX90640_Feather_M4_breadboard_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/087/386/medium640/adafruit_products_MLX90640_Feather_M4_breadboard_bb.png?1579806367)

## Python Computer Wiring

Since there are _dozens_ of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, [please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Here's the Raspberry Pi wired with I2C:

- **Pi 3V** &nbsp;to&nbsp;**sensor VCC (red wire)**
- **Pi GND** &nbsp;to&nbsp;**sensor GND (black wire)**
- **Pi SCL** &nbsp;to&nbsp;**sensor SCL (yellow wire)**
- **Pi SDA** &nbsp;to&nbsp;**sensor SDA (blue wire)**

![adafruit_products_MLX90640_RasPi_STEMMA_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/087/387/medium640/adafruit_products_MLX90640_RasPi_STEMMA_bb.png?1579806426)

![adafruit_products_MLX90640_RasPi_breadboard_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/087/388/medium640/adafruit_products_MLX90640_RasPi_breadboard_bb.png?1579806449)

## CircuitPython Installation of MLX90640 Library

You'll need to install the&nbsp;[Adafruit CircuitPython MLX90640](https://github.com/adafruit/Adafruit_CircuitPython_MLX90640) library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://circuitpython.org/libraries).&nbsp; Our CircuitPython starter guide has [a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

You'll need to manually install the necessary libraries from the bundle:

- **adafruit\_mlx90640.mpy**
- **adafruit\_bus\_device**

Before continuing, make sure your board's **lib** folder has the **adafruit\_mlx90640.mpy,** and **adafruit\_bus\_device** files and folders **&nbsp;** copied over.

## Python Installation of MLX90640 Library

You'll need to install the **Adafruit\_Blinka** library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3.&nbsp;[Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following command:

- `sudo pip3 install adafruit-circuitpython-mlx90640`

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

## CircuitPython & Python Usage

To demonstrate the usage of the sensor we'll run the `mlx90640_simpletest.py` program which prints the temperatures or shows them as ASCII. As this example is too complicated to run from the REPL, you'll save the following code to your board as **code.py** and connect to the serial console to see the output.

https://github.com/adafruit/Adafruit_CircuitPython_MLX90640/blob/main/examples/mlx90640_simpletest.py

![](https://cdn-learn.adafruit.com/assets/assets/000/087/390/medium800/adafruit_products_MLX90640_simpletest_serial_ASCII.png?1579809714)

If you change the values for the variables at the top of the program, you can switch from printing out an ASCII image to printing out the temperatures in a grid. Change `PRINT_TEMPERATURES` to `True` and `PRINT_ASCIIART` to `False`, so that the two lines are as follows:

```python
PRINT_TEMPERATURES = True
PRINT_ASCIIART = False
```

Connect to the serial console to see the temperatures printed out in a grid. Fitting them all in a proper grid involved making my terminal window significantly larger than the default size.

![](https://cdn-learn.adafruit.com/assets/assets/000/087/391/medium800/adafruit_products_MLX90640_simpletest_serial_prints.png?1579809895)

That's all there is to using the MLX90640 with CircuitPython!

# Adafruit MLX90640 IR Thermal Camera

## Python Docs

# Adafruit MLX90640 IR Thermal Camera

## CircuitPython Thermal Camera

The MLX90640 comes with STEMMA QT/QWIIC connectors which makes it super simple to plug into projects with no soldering needed. Adafruit sells a [STEMMA to STEMMA QT cable](https://www.adafruit.com/product/4424) that allows you to plug this breakout into the STEMMA connector found on a number of Adafruit microcontroller boards, including PyBadge and PyGamer. The following example uses the PyBadge or PyGamer and the MLX90640 to create a super easy-to-assemble thermal camera with a display!

## CircuitPython Microcontroller Wiring

First wire up a MLX90640 to your PyBadge or PyGamer exactly as shown below. Here's an example of wiring a PyBadge to the sensor with I2C using the [STEMMA to STEMMA QT cable](https://www.adafruit.com/product/4424):

- **Plug the larger end (STEMMA/Grove) of the cable into the PyBadge/PyGamer.**
- **Plug the smaller end (STEMMA QT) of the cable into the MLX90640.**

![adafruit_products_MLX90640_PyBadge_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/087/398/medium640/adafruit_products_MLX90640_PyBadge_bb.png?1579812185)

## CircuitPython Installation of Additional Libraries

On the previous page, you installed the [Adafruit CircuitPython MLX90640](https://github.com/adafruit/Adafruit_CircuitPython_MLX90640) library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries to use this example -- carefully follow the steps to find and install these libraries from [Adafruit's CircuitPython library bundle](https://circuitpython.org/libraries).&nbsp; Our CircuitPython starter guide has [a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

You'll need to manually install **two additional** libraries from the bundle:

- **adafruit\_display\_text**
- **simpleio.mpy**

Before continuing, make sure your board's **lib** folder has the **adafruit\_mlx90640.mpy,**  **adafruit\_bus\_device, adafruit\_display\_text&nbsp;** and&nbsp; **simpleio.mpy** files and folders **&nbsp;** copied over.

![adafruit_products_MLX90640_demo_lib_folder.png](https://cdn-learn.adafruit.com/assets/assets/000/087/400/medium640/adafruit_products_MLX90640_demo_lib_folder.png?1579812544)

## CircuitPython PyBadge/PyGamer Thermal Camera

Save the following code to your PyBadge or PyGamer as **code.py**.

https://github.com/adafruit/Adafruit_CircuitPython_MLX90640/blob/main/examples/mlx90640_pygamer.py

Now point the thermal camera at various objects to see a heat map displayed on your board!

![](https://cdn-learn.adafruit.com/assets/assets/000/087/800/medium800/adafruit_products_MLX90640_CircuitPython_PyGamer_demo.jpg?1580328376)

# Adafruit MLX90640 IR Thermal Camera

## Downloads

## Files

- [MLX90640 datasheet](https://www.melexis.com/-/media/files/documents/datasheets/mlx90640-datasheet-melexis.pdf)
- [EagleCAD files on GitHub](https://github.com/adafruit/Adafruit-MLX90640-PCB)
- [3D model files on GitHub](https://github.com/adafruit/Adafruit_CAD_Parts/tree/master/4469%20MLX90640%20Stemma)
- [Fritzing object in Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20MLX90640%20Thermal%20Camera.fzpz)

# Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/087/514/medium800/adafruit_products_MLX90640_sch.png?1579903508)

# Fab Print
![](https://cdn-learn.adafruit.com/assets/assets/000/087/516/medium800/adafruit_products_MLX90640_fab_print.png?1579903608)


## Primary Products

### Adafruit MLX90640 IR Thermal Camera Breakout

[Adafruit MLX90640 IR Thermal Camera Breakout](https://www.adafruit.com/product/4407)
You can now add affordable heat-vision to your project and with an Adafruit MLX90640 Thermal Camera Breakout. This sensor contains a 24x32 array of IR thermal sensors. When connected to your microcontroller (or Raspberry Pi) it will return an array of 768 individual infrared temperature...

In Stock
[Buy Now](https://www.adafruit.com/product/4407)
[Related Guides to the Product](https://learn.adafruit.com/products/4407/guides)

## Guide Products

### Adafruit Feather M0 Express

[Adafruit Feather M0 Express](https://www.adafruit.com/product/3403)
At the Feather M0's heart is an ATSAMD21G18 ARM Cortex M0+ processor, clocked at 48 MHz and at 3.3V logic, the same one used in the new&nbsp;[Arduino Zero](https://www.adafruit.com/products/2843). This chip has a whopping 256K of FLASH (8x more than the Atmega328 or 32u4) and...

In Stock
[Buy Now](https://www.adafruit.com/product/3403)
[Related Guides to the Product](https://learn.adafruit.com/products/3403/guides)
### Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket

[Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket](https://www.adafruit.com/product/2478)
Add some jazz & pizzazz to your project with a color touchscreen LCD. This TFT display is 2.4" diagonal with a bright (4 white-LED) backlight and it's colorful! 240x320 pixels with individual RGB pixel control, this has way more resolution than a black and white 128x64...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2478)
[Related Guides to the Product](https://learn.adafruit.com/products/2478/guides)
### Full Sized Premium Breadboard - 830 Tie Points

[Full Sized Premium Breadboard - 830 Tie Points](https://www.adafruit.com/product/239)
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip in the middle and two power rails on both sides. You can pull the power rails off easily to make the...

In Stock
[Buy Now](https://www.adafruit.com/product/239)
[Related Guides to the Product](https://learn.adafruit.com/products/239/guides)
### STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable

[STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable](https://www.adafruit.com/product/4209)
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium Dupont male headers on the other. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert...

In Stock
[Buy Now](https://www.adafruit.com/product/4209)
[Related Guides to the Product](https://learn.adafruit.com/products/4209/guides)

## Related Guides

- [Adafruit Feather M0 Express](https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython.md)
- [I Vote(d) Pin](https://learn.adafruit.com/i-vote-d-pin.md)
- [Matrix Portal Money-Sensing Tip Jar](https://learn.adafruit.com/matrix-portal-money-sensing-tip-jar.md)
- [CircuitPython Libraries on any Computer with FT232H](https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h.md)
- [Working with Multiple Same Address I2C Devices](https://learn.adafruit.com/working-with-multiple-i2c-devices.md)
- [Scrambled Number Security Keypad](https://learn.adafruit.com/scrambled-number-security-keypad.md)
- [Quickstart IoT - Raspberry Pi Pico RP2040 with WiFi ](https://learn.adafruit.com/quickstart-rp2040-pico-with-wifi-and-circuitpython.md)
- [Blinka LED Sign](https://learn.adafruit.com/blinka-led-sign.md)
- [MLX90640 Thermal Camera with Image Recording](https://learn.adafruit.com/mlx90640-thermal-image-recording.md)
- [Single Channel LoRaWAN Gateway for Raspberry Pi](https://learn.adafruit.com/raspberry-pi-single-channel-lorawan-gateway.md)
- [Flying Faders](https://learn.adafruit.com/flying-faders.md)
- [Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython](https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython.md)
- [Adafruit STEMMA & STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt.md)
- [Quick-Start the Pico W WiFi with CircuitPython](https://learn.adafruit.com/pico-w-wifi-with-circuitpython.md)
- [Fruit Jam Video Music](https://learn.adafruit.com/fruit-jam-video-music.md)
- [Adafruit Feather HUZZAH ESP8266](https://learn.adafruit.com/adafruit-feather-huzzah-esp8266.md)
