In the far 2017, I participated (and won) in a challenge promoted by FLIR and the BeagleBoard.org Foundation. I used a FLIR Lepton3 module and a BeagleBone Blue to detect and track people using their temperature.
In this article, I will explain how to use the same Lepton3 module with an NVIDIA® Jetson™ Nano.
FLIR Lepton3
The FLIR Lepton® is a radiometric-capable LWIR camera solution that is smaller than a dime, fits inside a smartphone, and is one tenth the cost of traditional IR cameras. Using focal plane arrays of either 160×120 or 80×60 active pixels, Lepton easily integrates into native mobile-devices and other electronics as an IR sensor or thermal imager. The radiometric Lepton captures accurate, calibrated, and noncontact temperature data in every pixel of each image.
From FLIR website
The FLIR Lepton3 communicates with the host using two different communication channels:
- I2C to control the sensor settings
- SPI to send thermal image data
The breakout board
The FLIR Lepton3 module requires a breakout board to connect it to our device. I use the GroupGets FLIR breakout board v1.4. All required Lepton system voltages, I2C pull-ups, and the clock is provided by this board so you can focus on your application software and not the Lepton setup hardware. Recently the new breakout board v2 has been released with a useful VSINC
signal and other useful features, that allow realizing more stable communication drivers.
Connection
The schematic of the connections is reported below
Lepton3 PIN | Lepton3 NAME | Color | Jetson Nano NAME | Jetson Nano PIN |
1 | CS | Green | SPI1-CS0 | 24 |
2 | MOSI | – | N.C. | N.C. |
3 | MISO | Yellow | SPI1-MISO | 21 |
4 | CLK | White | SPI1-CLK | 23 |
5 | GND | Black | GND | 6 |
6 | VIN | Red | 3V3 | 1 |
7 | SDA | Orange | I2C1-SDA | 27 |
8 | SCL | Brown | I2C1-SCL | 28 |
I created a simple carrier board using a protoboard to keep the FLIR Lepton 3 vertical, but the cables can be directly connected to the pin headers of the breakout board v1.4.
An optional resistor of 10KΩ is connected between MOSI and GND to keep the connection stable.
If you are curious about the rear single pin… it’s a GND test point, useful to connect the GND of the probe of the oscilloscope to analyze the status of each signal.
Enable SPI
The first operation to perform is enabling one SPI port on the Jetson™ Nano. The operation is quite simple, there is a very good guide to follow and I will not replicate every step here, just go to visit the JetsonHacks blog and follow the guidance of my friend kangalow about using the Jetson-IO tool to enable the SPI1 port available on the PINS 19,21,23,24,26 of the expansion header (J41) of the NVIDIA® Jetson™ Nano Developer Kit.
Change SPI buffer size
The default buffer size used for SPI communication is set to 4096 bytes by the spidev
module. Lepton3 requires 20KB of buffer to retrieve a full segment of data that composes the thermal image.
To change the size of the SPI buffer we have two methods. The first is temporary and the default buffer size will be restored after the next reboot, the second is permanent.
Temporary method
First of all, remove the spidev
module from the Kernel
$ sudo rmmod spidev
then reload the module setting the required parameter
$ sudo modprobe spidev bufsize=20480
Permanent method
To permanently set the value of the SPI buffer you must create a configuration file for modeprobe
$ sudo gedit /etc/modprobe.d/spidev.conf
Enter the following line
options spidev bufsiz=20480
Save and reboot the Jetson Nano
SPI Buffer size check
To be sure that the buffer size of the SPI has the correct value we can check the content of the file /sys/module/spidev/parameters/bufsiz
using the command
$ cat /sys/module/spidev/parameters/bufsiz
if you correctly followed the configuration procedure, the output should be 20480
.
Check I2C communication
To verify that the I2C cables are correctly connected you can use the command
$ i2cdetect -y -r 0
the I2C interface of the FLIR Lepton3 module should reply at address 0x2a
0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- 2a -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
Protective case
The Lepton3 breakout board is placed inside a protective 3D-printed case that I designed 3 years ago. It is available on Thingiverse.
Software
A GitHub repository is available that contains a library driver to control the Lepton3 by I2C and to get the thermal images by SPI.
The repository contains a sample demo that illustrates how to control the sensor features, how to acquire thermal images and how to display them using OpenCV.
The repository contains also a real world application that illustrates how to convert raw data values to real temperature values.
A useful application for COVID-19
In this strange period of COVID-19, a useful application for a thermal image is to measure the human temperature and alert in case it overcomes the “security value” of 37.5°C. The application is available in the Github repository and illustrates how to measure the person’s temperature and send visual alarms in case of possible fever.
The application allows “simulate fever” by adding °C to the temperatures that are in the range of human temperature.
The code is self-explaining and fully commented on, but you can write me an email if something is not clear. I will be happy to discuss it.
Now it’s time for images and videos, which are always better than many words.
Enjoy my work and STAY SAFE.