Lepton 3 port of basic capture code for Raspberry Pi

2,984 views
Skip to first unread message

Luke Van Horn

unread,
Jul 5, 2017, 2:45:19 AM7/5/17
to Flir Lepton
A work in progress.  I had trouble finding examples, so I thought I would share. 

https://github.com/lukevanhorn/Lepton3

Luke Van Horn

unread,
Jul 24, 2017, 9:55:14 AM7/24/17
to Flir Lepton
Update:  

I've created a more stable version that works with the pi zero and earlier v1/v2 types.

Also, I've added two other projects: 

1) Mini web server.  The image is displayed in a browser with the canvas element.  

2) Initial work on I2C/TWI control of the lepton.  

Alex G

unread,
Jul 26, 2017, 3:46:22 AM7/26/17
to Flir Lepton
Bless you, Luke Van Horn

Jin

unread,
Aug 7, 2017, 4:09:22 AM8/7/17
to Flir Lepton
Dear Luke, 
Thanks for your sharing. But i have encountered problems, since i get error messages from all source codes. It alerts that "can't read spi data:message too long". Could you give me any advisories on this?

Luke Van Horn

unread,
Aug 12, 2017, 2:21:27 PM8/12/17
to Flir Lepton
Hi Oli,

I've not encountered this error.  Did you increase the buffer size in the /boot/cmdline.txt ?  

"spidev.bufsiz=131072"

Oli

unread,
Aug 23, 2017, 11:25:26 PM8/23/17
to Flir Lepton

Hi Luke,

Yes i've already added that line in /boot/cmdline.txt and reboot as you described in github. 
However, still in the same errors as before, like a screenshot below.


Luke Van Horn

unread,
Aug 24, 2017, 5:59:59 PM8/24/17
to Flir Lepton
Hi Oli,

Try running this:  cat /sys/module/spidev/parameters/bufsiz
This should report the current bufsiz.

Older raspbian builds may need to have the bufsiz changed here: /etc/modprobe.d/spidev.conf  (it shouldn't exist if you have a newer build)

Here's the discussion where I found some help:  https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=124472

-Luke
Message has been deleted

Oli

unread,
Aug 25, 2017, 5:28:12 AM8/25/17
to Flir Lepton
Dear Luke,
Thanks to your codes, i can upload the pictures into http. Do you know how should i approach to increase the frequency of uploading higher than now?

Myzhar

unread,
Aug 25, 2017, 8:47:35 AM8/25/17
to Flir Lepton
Hi Luke,

a curiosity: how long are your I2C and SPI cables? I'm using your code on BeagleBone Blue and I have a lot of frame dropping due to loss of synchronization and I think that my cables are too long for VoSPI.

Thank you
Walter

On Wednesday, July 5, 2017 at 8:45:19 AM UTC+2, Luke Van Horn wrote:

Luke Van Horn

unread,
Aug 27, 2017, 5:42:07 PM8/27/17
to Flir Lepton
Hi Oli, I'm glad you have it working!  

Here's a few approaches for updating the screen (I'm planning to test these this week)

1. Use ajax request to poll for the lepton.js file every few seconds, then redraw the canvas.

2. setup websocket connection between the rpi and client(s).  Set the pi to continually read frames from the lepton and push new data to the clients as they are available. 

3. encapsulate as a video stream using ffmpeg and steam to the browser using via video tag. 

Luke

Luke Van Horn

unread,
Aug 27, 2017, 5:57:47 PM8/27/17
to Flir Lepton
Hi Walter,

My spi cables are ~8 inches.  This feels a bit long, but it seems to be working. I am pulling the unused MOSI line to ground as suggested in the manual (with a 10k resistor).

Have you tried using GPIO3 pulse to help sync?  

-Luke

Myzhar

unread,
Aug 28, 2017, 2:23:22 AM8/28/17
to Flir Lepton
Hi Luke,

8 inches??? I thought that my 10cm cables were exaggerated ^_^

The GPIO3 pulse to help Sync... can be useful. I must understand how to use it with BeagleBone Blue...
Can you reach good timing using sync pulse? Are you polling the signal continuosly or are you using somewhat similar to interrupt?

Walter

Myzhar

unread,
Aug 29, 2017, 3:37:17 AM8/29/17
to Flir Lepton
Hi Luke,

a curiosity: why are you reading using a SPI buffer sized 118080 bytes?

I tried to figure out why that value, but I cannot find a motivation.

To resume: you are reading a complete Data Segment using a single full read to avoid to lose a single Data Fragment.

From what I know we have these possibility for a segment size:
  • Raw14 No Telemetry - Packet Lenght: 164bytes - Packets per segment: 60 -> 9840 bytes
  • Raw14 Telemetry    - Packet Lenght: 164bytes - Packets per segment: 61 -> 10004 bytes
  • RGB88 No Telemetry - Packet Lenght: 244bytes - Packets per segment: 60 -> 14640 bytes
  • RGB88 Telemetry    - Packet Lenght: 244bytes - Packets per segment: 61 -> 14884 bytes (telemetry not valid, but present)
The data stream size is 10 times less than the buffer you have chosen... there is something missing for me.

Even considering the whole frame we have 59536 bytes as maximum data... 

Thank you
Walter

Ben Kluwe

unread,
Aug 29, 2017, 4:47:54 AM8/29/17
to Flir Lepton
Hi Myzhar,

It's not the maximum that counts, if you do 118080/9840 you get 12, which is further divisible by 4, so he reads in 3 frames at once per say. However, you also need to consider that some of the data will be discard packets, so it will probably be able to capture 1-2 frames at once.

Ben

Myzhar

unread,
Aug 29, 2017, 6:14:45 AM8/29/17
to Flir Lepton
You are right, I figured out that in this way he get the unique frame and the two invalid frames that follows it.

But it wastes time... I'm trying instead to read segment by segment and use the time between one segment and the next to not lose sync.

You can find my code in this repository:
https://github.com/Myzhar/Lepton3_BBB
the branch is " test_from_qt"

In this way you can use the GPIO3 signal that in Lepton3 is sent each new segment (not each frame like former sensor version).

Luke Van Horn

unread,
Aug 29, 2017, 6:37:46 PM8/29/17
to Flir Lepton
Yup, I'm reading 3 frames at once to try to ensure getting at least one valid frame.  This is to overcome (what I think is) the speed issue with the pi zero -- I couldn't read one segment at a time fast enough to keep up with the stream. 

Luke Van Horn

unread,
Aug 31, 2017, 7:44:04 PM8/31/17
to Flir Lepton
Hi Oli, 

I've updated the code to use ajax.  It defaults to refreshing every 5 seconds, but it's easy to change that in the index.html. 

Cheers,
Luke

Yogesh Murthy

unread,
Jan 13, 2018, 5:25:59 AM1/13/18
to Flir Lepton
HI Walter!

Just curious. Why are you using a delay of 50 in the spi_ioc_transfer structure? Luke uses as delay  the maximum 16-bit integer. What is the logic behind this?

Thanks,
Yogesh

Luke Van Horn

unread,
Jan 15, 2018, 5:04:37 PM1/15/18
to Flir Lepton
Hi Yogesh, 

I recently updated the project and have changed the delay back to 0.  --I think I had increased it while troubleshooting sync issues.  I also started setting the priority (SHED_FIFO) and this appears to help a lot. I still get an occasional segmentation fault, but i think this is more related to the web server.

I haven't updated the capture code yet, these changes are only in the web folder. 

Thanks,
Luke

AB Peter

unread,
Jan 15, 2018, 10:41:32 PM1/15/18
to Flir Lepton

Hi!

Have not examined the code that close yet. So sorry if my question is a bit stupid. Little experience in raspberry so...

The videos I´we seen on lepton there seems to be an automatic «color balance» so that very hot objects entering the picture will make the less hot items all seem cool. Is this also the case for this code? Is the purpose of this just so that the displaying of the image will make more sense? The reason for my question is that I wanted to check if it might be possible to make some sort of detection of temperatures that would be close to body temperature.

Mark DeLoura

unread,
Feb 1, 2018, 7:20:21 PM2/1/18
to Flir Lepton
Thanks Luke - yours was the first piece of code I was able to get working properly on my Pi 3 with Lepton 3, after a number of battles with other projects. 
Thanks!
  ---Mark

fboris

unread,
Mar 13, 2018, 5:14:56 AM3/13/18
to Flir Lepton
Hi Myzhar,

Did you use GPIO 3 eventually? I read your code. and found there are no function accessing gpio 3. 
Actually lepton 3 breakout board v1.4 didn't have pin can connect to the raspberry pi.

I used your code on raspberry pi 3. It still needed to resync in every 1~2 second(which is  a lot).


Myzhar於 2017年8月29日星期二 UTC+8下午6時14分45秒寫道:

Ophir Shechter

unread,
Jun 5, 2018, 11:55:59 AM6/5/18
to Flir Lepton
how can I reboot the lepton3 ?
It get out of sync every few tens of images ( sometime more) and the segments are very slow or not at all.

Luke Van Horn

unread,
Jun 5, 2018, 12:21:42 PM6/5/18
to Flir Lepton
Unfortunately, this requires toggling gpio3 on the lepton breakout which isn't wired to a pin. I usually have to pull the module out of the socket to get it to properly reset.  

I plan to setup a way to cycle power to the lepton via power transistor/gpio.  I think this will be the most effective. 

Ben Kluwe

unread,
Jun 5, 2018, 12:38:46 PM6/5/18
to Flir Lepton
I suggest searching the forum for a soft reset function, the function is called something like LEP_OEMReboot. I have tried and succeeded in doing a soft reboot of the lepton sensor.

Ben

Ophir Shechter

unread,
Jun 5, 2018, 12:41:18 PM6/5/18
to Ben Kluwe, Flir Lepton
Can you direct me to the c code
Thanks

Amadeus Rong

unread,
Apr 23, 2019, 5:00:42 AM4/23/19
to Flir Lepton
Hi Luke,

thanks a lot for sharing!!! Your code is the only one I found which enables me to read from Lepton 3.5 boards.

Have you ever tried reading via another spi device? Simply changing line 63 to ""static const char *device = "/dev/spidev1.0";" doesn't work for me. I get following error:
"can't set spi mode: Invalid argument
Aborted"
My Raspi is a zero W and the additional SPI devices were activated by adding "dtoverlay=spi1-3cs" to /boot/config.txt

Best regards,
Amadeus

Am Montag, 24. Juli 2017 15:55:14 UTC+2 schrieb Luke Van Horn:
Update:  

I've created a more stable version that works with the pi zero and earlier v1/v2 types.

Also, I've added two other projects: 

1) Mini web server.  The image is displayed in a browser with the canvas element.  

2) Initial work on I2C/TWI control of the lepton.  





Amadeus Rong

unread,
Jun 3, 2019, 9:57:01 AM6/3/19
to Flir Lepton
Ok,
after changing "static uint8_t mode = SPI_CPOL | SPI_CPHA;" to "static uint8_t mode;" it now works with spi devices 0.1 and 1.0.

Luke Van Horn

unread,
Jun 3, 2019, 10:52:47 AM6/3/19
to Amadeus Rong, Flir Lepton
Awesome, thanks for the follow up. Glad you got it working.

--
You received this message because you are subscribed to a topic in the Google Groups "Flir Lepton" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/flir-lepton/y7333qnWI9M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to flir-lepton...@googlegroups.com.
Visit this group at https://groups.google.com/group/flir-lepton.
To view this discussion on the web visit https://groups.google.com/d/msgid/flir-lepton/feb50134-e79c-4973-a5a2-b814dbcea099%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexandre Cherpillod

unread,
Aug 6, 2019, 3:36:14 PM8/6/19
to Flir Lepton
Hi Amadeous,

I'm glad to read that you where able to get the image from the Lepton 3.5 using the code of Luke Van Horn.
I was wondering if you get issues with latency/framerate (9Hz) or other side issue?
Do you think we could run other algorithm in parallel or the raspberry Pi Zero is already overloaded with the dialog with the Lepton 3.5?

Many thanks, Alex
Reply all
Reply to author
Forward
0 new messages