Cost and ease of use were considered most when selecting a sensor for this guide. To save yourself the trouble of fabricating your own breakout circuitry and writing your own libraries it is best to make use of what is already available.
Companies such as Adafruit and Sparkfun produce breakout boards and supporting libraries for sensors such as the AMG8833and the MLX90640.
Panasonic manufactures the AMG8833, which is capable of sampling an 8x8 grid of 64 individual temperature readings up to 10 times per second. It can detect temperatures ranging from 0 to 80 degrees Celsius.
The MLX90640 is made by a company called Melexis and while costlier it is superior compared to the AMG8833. It has a resolution of 32x24 and can sample 768 temperature readings up to 64 times per second, detecting temperatures as low as -40 degrees Celsius and as high as 300 degrees Celsius.
At the time of this writing, the MLX90640 breakout board is sold out with no option to backorder, so I will demonstrate the AMG8833 breakout board produced by Adafruit, as well as the python library they provide.
Regardless of which supplier you source the sensor from it will likely come with header pins that are not pre-soldered. For our purposes, it will be necessary to solder them in place.
Something the breakout boards for the AMG8833 and the MLX90640 have in common is the I2C protocol they use to communicate with the Raspberry Pi. The protocol uses one wire for bi-directional serial data transmission and another wire to supply a clock signal.
To avoid damaging the sensor or the Pi perform the following with the Pi powered off.
- Use one of the jumper wires to connect the Vin pin on the sensor to pin 1 on the Pi.
- Connect the GND pin to pin 9
- Connect the SDA to pin 3
- Connect the SCL to pin 5 using the remaining wires.
A fresh install of Raspberry Pi OS has the I2C interface disabled by default. It will be necessary to turn it on.
- Open a terminal window on the Raspberry Pi and run the following:
Select Interface Options then I2C.
Select Yes to enable the interface.
Next, we will install a python library that will do the heavy lifting of turning the signal input from the sensor into useful data. If you are using an MLX90640 based sensor then you may have to check with the manufacturer for the appropriate library. For the AMG8833 based sensor, we will install a library provided by Adafruit.
In a terminal window run the following:
This will install the library necessary for interfacing with the sensor.
sudo pip3 install adafruit-circuitpython-amg88xx
The following libraries are only needed to run the graphical example code provided by Adafruit. Run the following commands in a terminal:
sudo apt-get install python-dev libatlas-base-dev
sudo pip3 install scipy pygame colour
- The first command installs dependencies for NumPy, which is a component of scipy.
- Scipy is a data library that will be used in the example code to interpolate pixel data.
- Pygame is used primarily for creating games, but here it will be used to render sensor data to the screen.
- Colour is a library that simplifies the manipulation of color data.
We are almost ready to see some output.
We will fetch the example code with this command:
Change to the example code directory:
git clone https://github.com/adafruit/Adafruit_CircuitPython_AMG88xx
Finally, run the example:
You should see a pygame render window that shows a color representation or "heat map" of the sensor data. Cooler temperatures are represented with blue and green hues while warmer temperatures are shown with yellow, orange, and red.
In this configuration, the sensor and the Pi are acting as a low-resolution thermal camera. Take a look at some of the other scripts provided in the example folder to see how you can work this sensor into your own code and your own projects. Like what about an awesome setting up a Raspberry Pi security camera that uses thermal imaging?!
Nothing can slow down the Raspberry Pi Foundation, as even in 2021, the team managed to serve up a selection of new Raspberry Pi boards, modules, and fun accessories.