Thermal Images on Jetson™ Nano with FLIR Lepton3

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
Flir Lepton3

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

FLIR Lepton3 to NVIDIA® Jetson™ Nano Developer Kit connection
Lepton3
PIN
Lepton3
NAME
ColorJetson Nano
NAME
Jetson Nano
PIN
1CSGreenSPI1-CS024
2MOSIN.C.N.C.
3MISOYellowSPI1-MISO21
4CLKWhiteSPI1-CLK23
5GNDBlackGND6
6VINRed3V31
7SDAOrangeI2C1-SDA27
8SCLBrownI2C1-SCL28
Connection table
Lepton3 side
Jetson Nano side

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.

Carrier board top
Carrier board bottom

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.

The two parts of the protective case
Lepton3 safe inside its protective case

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.

Fever Normal
Simulated Fever Warning
Simulated Fever Alert

Enjoy my work and STAY SAFE.

Comments are closed.