Adafruit MLX90640 IR Thermal Camera Created by Kattni Rembor Last updated on 2020-01-29 08:52:52 PM UTC
Overview 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. There are two versions: one with a wider 110°x70° field of view (https://adafru.
This part will measure temperatures ranging from -40°C to 300°C 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.
effect when moving the sensor around - the effect isn't noticeable when things move slowly. 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 SparkFun qwiic (https://adafru.it/Fpw) compatible STEMMA QT (https://adafru.it/Ft4) connectors for the I2C bus so you don't even need to solder! Just plug-n-play with any of our STEMMA QT (JST SH) cables.
Pinouts 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. 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.
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. STEMMA Connectors STEMMA QT (https://adafru.
Arduino I2C Wiring Use this wiring to connect via I2C interface. Connect board VIN (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead. Connect board GND (black wire) to Arduino GND Connect board SCL (yellow wire) to Arduino SCL Connect board SDA (blue wire) to Arduino SDA The final results should resemble the illustration above, showing an Adafruit Metro development board.
Click the Manage Libraries... menu item, search for Adafruit MLX90640, and select the Adafruit MLX90640 library: Then follow the same process for the Adafruit BusIO library. Finally follow the same process for the Adafruit Unified Sensor library: Load Example Open up File -> Examples -> Adafruit MLX90640 -> MLX90640_simpletest and upload to your Arduino wired up to the sensor.
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.
while (!Serial) delay(10); Serial.begin(115200); delay(100); Serial.println("Adafruit MLX90640 Simple Test"); if (! mlx.begin(MLX90640_I2CADDR_DEFAULT, &Wire)) { Serial.println("MLX90640 not found!"); while (1) delay(10); } Serial.println("Found Adafruit MLX90640"); Serial.print("Serial number: "); Serial.print(mlx.serialNumber[0], HEX); Serial.print(mlx.serialNumber[1], HEX); Serial.println(mlx.serialNumber[2], HEX); //mlx.setMode(MLX90640_INTERLEAVED); mlx.setMode(MLX90640_CHESS); Serial.
float t = frame[h*32 #ifdef PRINT_TEMPERATURES Serial.print(t, 1); Serial.print(", "); #endif #ifdef PRINT_ASCIIART char c = '&'; if (t < 20) c = ' '; else if (t < 23) c = else if (t < 25) c = else if (t < 27) c = else if (t < 29) c = else if (t < 31) c = else if (t < 33) c = else if (t < 35) c = else if (t < 37) c = Serial.print(c); #endif } Serial.println(); } } © Adafruit Industries + w]; '.'; '-'; '*'; '+'; 'x'; '%'; '#'; 'X'; https://learn.adafruit.
Arduino Docs Arduino Docs (https://adafru.it/IzA) © Adafruit Industries https://learn.adafruit.
Arduino 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://adafru.it/IDk) that allows you to plug this breakout into the STEMMA connector found on a number of Adafruit microcontroller boards, including PyBadge and PyGamer.
#include #include "Adafruit_Arcada.
0xBEE0,0xBEE0,0xC6E0,0xC6E0,0xCEE0,0xCEE0,0xD6E0,0xD700,0xDF00,0xDEE0, 0xDEC0,0xDEA0,0xDE80,0xDE80,0xE660,0xE640,0xE620,0xE600,0xE5E0,0xE5C0, 0xE5A0,0xE580,0xE560,0xE540,0xE520,0xE500,0xE4E0,0xE4C0,0xE4A0,0xE480, 0xE460,0xEC40,0xEC20,0xEC00,0xEBE0,0xEBC0,0xEBA0,0xEB80,0xEB60,0xEB40, 0xEB20,0xEB00,0xEAE0,0xEAC0,0xEAA0,0xEA80,0xEA60,0xEA40,0xF220,0xF200, 0xF1E0,0xF1C0,0xF1A0,0xF180,0xF160,0xF140,0xF100,0xF0E0,0xF0C0,0xF0A0, 0xF080,0xF060,0xF040,0xF020,0xF800,}; uint16_t displayPixelWidth, displayPixelHeight;
t = min(t, MAXTEMP); t = max(t, MINTEMP); uint8_t colorIndex = map(t, MINTEMP, MAXTEMP, 0, 255); colorIndex = constrain(colorIndex, 0, 255); //draw the pixels! arcada.display->fillRect(displayPixelWidth * w, displayPixelHeight * h, displayPixelHeight, displayPixelWidth, camColors[colorIndex]); } } Serial.print((millis()-timestamp) / 2); Serial.println(" ms per frame (2 frames per display)"); Serial.print(2000.0 / (millis()-timestamp)); Serial.
Python & CircuitPython It's easy to use the MLX90640 sensor with Python and CircuitPython, and the Adafruit CircuitPython MLX90640 (https://adafru.it/IBv) 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://adafru.it/BSN).
Pi 3V to sensor VCC (red wire) Pi GND to sensor GND (black wire) Pi SCL to sensor SCL (yellow wire) Pi SDA to sensor SDA (blue wire) CircuitPython Installation of MLX90640 Library You'll need to install the Adafruit CircuitPython MLX90640 (https://adafru.it/IBv) library on your CircuitPython board. First make sure you are running the latest version of Adafruit CircuitPython (https://adafru.it/Amd) for your board.
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.
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: 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.
Python Docs Python Docs (https://adafru.it/IxD) © Adafruit Industries https://learn.adafruit.
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://adafru.it/IDk) that allows you to plug this breakout into the STEMMA connector found on a number of Adafruit microcontroller boards, including PyBadge and PyGamer.
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 and simpleio.mpy files and folders copied over. CircuitPython PyBadge/PyGamer Thermal Camera Save the following code to your PyBadge or PyGamer as code.py.
def MakeHeatMapColor(): for c in range(number_of_colors): value = c * (NUM_COLORS-1) / last_color idx1 = int(value) # Our desired color will be after this index. if idx1 == value : # This is the corner case red = color[idx1][0] green = color[idx1][1] blue = color[idx1][2] else: idx2 = idx1+1 # ... and before this index (inclusive). fractBetween = value - idx1 # Distance between the two indexes (0-1).
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_4_HZ frame = [0] * 768 while True: stamp = time.monotonic() try: mlx.getFrame(frame) except ValueError: # these happen, no biggie - retry continue # print("Time for data aquisition: %0.2f s" % (time.
© Adafruit Industries https://learn.adafruit.
Downloads Files MLX90640 datasheet (https://adafru.it/IAR) EagleCAD files on GitHub (https://adafru.it/IAS) Fritzing object in Adafruit Fritzing Library (https://adafru.it/IAT) Schematic Fab Print © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2020-01-29 08:52:52 PM UTC Page 30 of 30