cosmac / LePi

LePi is a lightweight library for FLIR Lepton (2, 2.5 and 3) and Raspberry pi.
MIT License
27 stars 10 forks source link

SPI #3

Open 3YY3 opened 6 years ago

3YY3 commented 6 years ago

Hi, I have a problem with running the program. When "Player" is executed in terminal can be seen that it opens and closes the SPI communication to the infinity. Some frames are visible on the screen (like 1 frame per 5 sec.), rest it is looking like the camera is freezed. What can cause this issue? I´m using Rpi Zero, Jessie, Lepton v3. The processor indicator is not even windy, shows around 40% used computing capacity. When I try to run "PlayerThread" the processor is used whole, 100%. Almost no frames can be seen and it makes Rpi unuseable unless hard restart is done.

cosmac commented 6 years ago

"When I try to run "PlayerThread" the processor is used whole, 100%." PlayerThread is using a parallel thread to grab the frames from Lepton. In this way, when you ask for a frame, the latest one read will be returned. Anyway, your Rpi Zero has one core only, so the parallel thread is not actually parallel. The multi-threading overhead while using a single core CPU is too high. For this reason, I would not recommend Rpi Zero with the parallel interface. Please use the serial one.

cosmac commented 6 years ago

Now, I never tested my lib with Rpi Zero (only Rpi 2 and 3). My guess, the SPI resets can be the result of a loss in sync with Lepton. Please try to increase the number of packets read in one SPI read call. e.g. set packets_per_read to 5, you can find this in LeptonCommon.h

3YY3 commented 6 years ago

Well, increasing the number of packets_per_read helped a little. But it is really only small quallity improvement. I found that Rpi Zero has problem with electric interference. Output is much better, if I disconnect usb keyboard. So I think that missing frames is not a software problem but hardware.

cosmac commented 6 years ago

That could be the case. If I put my hands on a Rpi Zero I will try to debug this behavior too. Thanks !

3YY3 commented 6 years ago

Uhh, have everything including battery power source inside a faraday cage, yet still not working properly. After a short reading of Rpi 2,3 and Zero differences I have to ask: how the spi speed is set in the program? I have only found setting the speed in Hz in LeptonCommon.h but how is this value interpreted by Rpi? How does it sets the divider? I have tried to find this reading though the program with no success.

cosmac commented 6 years ago

Searching the web, I found many problems with the SPI, since this is based on the CLK and a pre-fixed set of dividers. Anyway, here is the line that I use to set the speed in Hz: https://github.com/cosmac/LePi/blob/master/lib/leptonAPI/src/LeptonUtils.cpp#L221 However, the speed is not guaranteed. My understanding is that it really depends on the closest (and lowest) possible value. Here is an extract from RPi hardware documentation:

cdiv speed 2 125.0 MHz 4 62.5 MHz 8 31.2 MHz 16 15.6 MHz 32 7.8 MHz ........................... When asking for say 24 MHz, the actual speed will be 15.6 MHz.

I will read more on this.

3YY3 commented 6 years ago

Yeah, I have read something like that on the web. However, I will try to get my hands on Rpi3 :D