groupgets / LeptonModule

Code for getting started with the FLIR Lepton breakout board
https://groupgets.com/manufacturers/flir/products/flir-lepton
BSD 2-Clause "Simplified" License
315 stars 195 forks source link

Red square on black screen - raspberrypi_video #70

Open Henrikcox opened 4 years ago

Henrikcox commented 4 years ago

I've been trying to set up a Lepton Thermal Camera (breakout v1.4) with both a raspberry pi 3 and a zero W. I started with this wiring and setup guide and have been troubleshooting with all the suggestions mentioned in this thread with no luck.

Running sudo ./raspberrypi_video

Running sudo ./raspberrypi_capture [with output file name]

Running sudo ./raspberrypi_overlay [with options such as '-a 155']

Running sudo ./raspberrypi_qt

To troubleshoot I have:

In addition to LeptonModule (C/C++) I have also tried the same with pylepton (Python) with identical results.

Any insights and advice are appreciated in advance

hanifizzudinrahman commented 4 years ago

thx for the solution after this, i will try it...

hanifizzudinrahman commented 4 years ago

btw, i want to ask i have done with

in yours, we must Set DEBUG_LEPTON to true in the Lepton_thread.h script, then back to false but commented out the debug defines surrounding line 48, and changed 'sequence' to 'sequencex'

but, in mine there is no Lepton_thread.h but LeptonThread.h and the code is

#include "LeptonThread.h"

#include "Palettes.h" 
#include "SPI.h"
#include "Lepton_I2C.h"

#define PACKET_SIZE 164
#define PACKET_SIZE_UINT16 (PACKET_SIZE/2)
#define PACKETS_PER_FRAME 60
#define FRAME_SIZE_UINT16 (PACKET_SIZE_UINT16*PACKETS_PER_FRAME)
#define FPS 27;

LeptonThread::LeptonThread() : QThread()
{
}

LeptonThread::~LeptonThread() {
}

void LeptonThread::run()
{
    //create the initial image
    myImage = QImage(80, 60, QImage::Format_RGB888);

    //open spi port
    SpiOpenPort(0);

    while(true) {

        //read data packets from lepton over SPI
        int resets = 0;
        for(int j=0;j<PACKETS_PER_FRAME;j++) {
            //if it's a drop packet, reset j to 0, set to -1 so he'll be at 0 again loop
            read(spi_cs0_fd, result+sizeof(uint8_t)*PACKET_SIZE*j, sizeof(uint8_t)*PACKET_SIZE);
            int packetNumber = result[j*PACKET_SIZE+1];
            if(packetNumber != j) {
                j = -1;
                resets += 1;
                usleep(1000);
                //Note: we've selected 750 resets as an arbitrary limit, since there should never be 750 "null" packets between two valid transmissions at the current poll rate
                //By polling faster, developers may easily exceed this count, and the down period between frames may then be flagged as a loss of sync
                if(resets == 750) {
                    SpiClosePort(0);
                    usleep(750000);
                    SpiOpenPort(0);
                }
            }
        }
        if(resets >= 30) {
            qDebug() << "done reading, resets: " << resets;
        }

        frameBuffer = (uint16_t *)result;
        int row, column;
        uint16_t value;
        uint16_t minValue = 65535;
        uint16_t maxValue = 0;

        for(int i=0;i<FRAME_SIZE_UINT16;i++) {
            //skip the first 2 uint16_t's of every packet, they're 4 header bytes
            if(i % PACKET_SIZE_UINT16 < 2) {
                continue;
            }

            //flip the MSB and LSB at the last second
            int temp = result[i*2];
            result[i*2] = result[i*2+1];
            result[i*2+1] = temp;

            value = frameBuffer[i];
            if(value > maxValue) {
                maxValue = value;
            }
            if(value < minValue) {
                minValue = value;
            }
            column = i % PACKET_SIZE_UINT16 - 2;
            row = i / PACKET_SIZE_UINT16 ;
        }

        float diff = maxValue - minValue;
        float scale = 255/diff;
        QRgb color;
        for(int i=0;i<FRAME_SIZE_UINT16;i++) {
            if(i % PACKET_SIZE_UINT16 < 2) {
                continue;
            }
            value = (frameBuffer[i] - minValue) * scale;
            const int *colormap = colormap_ironblack;
            color = qRgb(colormap[3*value], colormap[3*value+1], colormap[3*value+2]);
            column = (i % PACKET_SIZE_UINT16 ) - 2;
            row = i / PACKET_SIZE_UINT16;
            myImage.setPixel(column, row, color);
        }

        //lets emit the signal for update
        emit updateImage(myImage);

    }

    //finally, close SPI port just bcuz
    SpiClosePort(0);
}

void LeptonThread::performFFC() {
    //perform FFC
    lepton_perform_ffc();
}
and also, there are no **DEBUG_LEPTON**  and 
**'sequence'**
 or 
**'sequencex'**
Henrikcox commented 4 years ago

The LeptonThread.h file I'm referring to is in the raspberrypi_qt folder (under software). You have the wrong file open.

Follow the third comment's example in this thread. Hopefully that works for you; I still have not been able to get mine working.

hanifizzudinrahman commented 4 years ago

i have try it but still wrong when try raspberrypi_qt the message error is "Error transfering SPI Packet" i have modified the code in LeptonThread.cpp

2019-12-09-173202_1440x900_scrot

Henrikcox commented 4 years ago

Yes that is one of the errors I'm getting right now too. Still have not found a solution to it I'm afraid.

hanifizzudinrahman commented 4 years ago

i use a new code from Frank

LEPTON 2.zip

I will say full thank you to you because, with this code, is absolutely make me happiest person in the world, hehehe...

But, there is little problem in my project (Lepton 2.5 with board V1.4 + Raspberry Pi 3 B) my schematic is

According with the suggestion above, i make some change in ....

when i run the Lepton-CaptureRaw, the result is good like this, but... SS 1

but..., sometimes when i try 10 times run this i can video it the thermal video and when i press the button "Snapsot" it will give me the .jpg picture (1-rgb.jpg, 2-rgb.jpg) and .bin format (1-raw.bin, 2-raw.bin) that this raw format will show a temperature value (i'm not yet with this) but 2 times will fail. The error is "Error transfering SPI packet" and the layer full of red. Can you help me with this? why this happen?

Henrikcox commented 4 years ago

I'm glad you're making progress with it. Is the LEPTON 2.zip file the same as the our_video.zip file from the top of that thread (https://groups.google.com/forum/#!topic/flir-lepton/GWHD1KMVYaE)?

I was following the same thing as you did but still get the red screen and either "Error transferring SPI packet" or "Packet reset counter hit 750." But I am running raspberrypi_video with sudo ./raspberrypi_video

Are you running a different file, how are you running it? I am not seeing where Lepton-CaptureRaw that you're running is.

gholibeigian commented 3 years ago

Hi, It seems very crazy, but when I changed the jumper wires with the short ones(shortest), I did not get this error anymore!