We have come out a design with image processing for extracting target frame and uploading to internet server. Checked it out at www.sglab.sg - total power consumption is dominated by the lepton module.
/* Variables *///Array to store one Lepton framebyte leptonFrame[164];//Array to store 80 x 60 RAW14 pixelsuint16_t rawValues[4800];
/* Methods */
/* Start Lepton SPI Transmission */void beginLeptonSPI() { //Begin SPI Transaction on alternative Clock SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0)); //Start transfer - CS LOW digitalWriteFast(15, LOW);}
/* End Lepton SPI Transmission */void endLeptonSPI() { //End transfer - CS HIGH digitalWriteFast(15, HIGH); //End SPI Transaction SPI.endTransaction();}
/* Reads one line (164 Bytes) from the lepton over SPI */boolean leptonReadFrame(uint8_t line, uint8_t seg) { bool success = true; //Receive one frame over SPI SPI.transfer(leptonFrame, 164); //Check for success if ((leptonFrame[0] & 0x0F) == 0x0F) { success = false; } else if (leptonFrame[1] != line) { success = false; } return success;}
/* Get one image from the Lepton module */void getTemperatures() { byte leptonError = 0; byte line; //Begin SPI Transmission beginLeptonSPI(); do { leptonError = 0; for (line = 0; line < 60; line++) { //Reset if the expected line does not match the answer if (!leptonReadFrame(line, segment)) { //Reset line to -1, will be zero in the next cycle line = -1; //Raise Error count leptonError++; //Little delay delay(1); //If the Error count is too high, reset the device if (leptonError > 100) { //Re-Sync the Lepton endLeptonSPI(); delay(186); beginLeptonSPI(); break; } } //If line matches answer, save the packet else { //Go through the video pixels for one video line for (int column = 0; column < 80; column++) { uint16_t result = (uint16_t)(leptonFrame[2 * column + 4] << 8 | leptonFrame[2 * column + 5]); //Save to array rawValues[column + (line * 80)] = result; } } } } while ((leptonError > 100) || (line != 60)); //End Lepton SPI endLeptonSPI();}Arduino sketches consist of C/C++ code.
Adaptation is easy:
-In your setup() function, do the SPI init stuff like setting the CS pin High (digitalWrite(cs,HIGH)) and start the SPI bus (SPI.begin()).
-In the loop() function, call the function getTemperatures(), so you will read out the 80x60 raw value array from the sensor in every cycle. Also do your image processing stuff like color conversion/display or the data transmission here.
That's all you need to know. Maybe you also need to configure the Lepton over I2C with the Teensy i2c_t3 library, but thats not necessary for basic functionality (RAW14 output).
So you may remove the segment from argument list or just set it to zero.
#include <Wire.h>
#include <SPI.h>
/* Variables */
//Array to store one Lepton frame
byte leptonFrame[164];
//Array to store 80 x 60 RAW14 pixels
uint16_t rawValues[4800];
/* Methods */
void setup() {
digitalWrite(10,HIGH); //digitalWrite(cs,HIGH);
Serial.begin(9600);
SPI.begin();
beginLeptonSPI();
}
void loop() {
getTemperatures();
}
/* Start Lepton SPI Transmission */
void beginLeptonSPI() {
//Begin SPI Transaction on alternative Clock
SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));
//Start transfer - CS LOW
//digitalWriteFast(15, LOW);
digitalWriteFast(10, LOW);
}
/* End Lepton SPI Transmission */
void endLeptonSPI() {
//End transfer - CS HIGH
//digitalWriteFast(15, HIGH);
digitalWriteFast(10, HIGH);
//End SPI Transaction
SPI.endTransaction();
}
/* Reads one line (164 Bytes) from the lepton over SPI */
boolean leptonReadFrame(uint8_t line) {
bool success = true;
//Receive one frame over SPI
SPI.transfer(leptonFrame, 164);
//Check for success
if ((leptonFrame[0] & 0x0F) == 0x0F) {
success = false;
}
else if (leptonFrame[1] != line) {
success = false;
}
return success;
}
/* Get one image from the Lepton module */
void getTemperatures() {
byte leptonError = 0;
byte line;
//Begin SPI Transmission
beginLeptonSPI();
do {
leptonError = 0;
for (line = 0; line < 60; line++) {
//Reset if the expected line does not match the answer
if (!leptonReadFrame(line)) {
//Reset line to -1, will be zero in the next cycle
line = -1;
//Raise Error count
leptonError++;
//Little delay
delay(1);
//If the Error count is too high, reset the device
if (leptonError > 100) {
//Re-Sync the Lepton
endLeptonSPI();
delay(186);
beginLeptonSPI();
break;
}
}
//If line matches answer, save the packet
else {
//Go through the video pixels for one video line
for (int column = 0; column < 80; column++) {
uint16_t result = (uint16_t)(leptonFrame[2 * column + 4] << 8
| leptonFrame[2 * column + 5]);
//Save to array
rawValues[column + (line * 80)] = result;
Serial.print(result); /// Here result seem to be equal always to 0 ???????????
}
Serial.println(" ");
}
}
} while ((leptonError > 100) || (line != 60));
//End Lepton SPI
endLeptonSPI();
}
#include <Wire.h>
#include <SPI.h>
//Array to store one Lepton frame
byte leptonFrame[164];
//Array to store 80 x 60 RAW14 pixels
uint16_t rawValues[4800];
//Define the CS port for your FLIR Lepton here
#define Lepton_CS 10
/* SPI and Serial debug setup */
void setup() {
//Also set all other SPI devices CS lines to Output and High here
pinMode(Lepton_CS, OUTPUT);
digitalWrite(Lepton_CS, HIGH);
//Start SPI
SPI.begin();
//Start UART
Serial.begin(115200);
//Serial.begin(9600);
}
/* Main loop, get temperatures and print them */
void loop() {
getTemperatures();
printValues();
}
/* Start Lepton SPI Transmission */
void beginLeptonSPI() {
//Begin SPI Transaction on alternative Clock
SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));
//Start transfer - CS LOW
digitalWriteFast(Lepton_CS, LOW);
}
/* End Lepton SPI Transmission */
void endLeptonSPI() {
//End transfer - CS HIGH
digitalWriteFast(Lepton_CS, HIGH);
//End SPI Transaction
SPI.endTransaction();
}