Teensy 3.2

751 views
Skip to first unread message

Philippe Rolland

unread,
Nov 8, 2015, 10:30:32 AM11/8/15
to Flir Lepton
Dear
I'm a newby, I'm looking for low power solution to use Lepton, Teensy 3.2 seem to be a good idea, but it's seem to me, many users, here,  don't find solution to reach  this goal.
Is someone managed to run correctly on Teensy 3.x ?
Best regards

Shanguo Lu

unread,
Nov 9, 2015, 6:28:38 AM11/9/15
to Flir Lepton
There will be lots of fat when we use a embedded OS, if you really desperate in reduce the power consumption. Lots resource required to keep the OS running, as compared to amount of resource for real task.

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.

Mike McRoberts

unread,
Nov 9, 2015, 9:05:12 AM11/9/15
to Flir Lepton
Phillipe i'm also trying to get the Flir Lepton working with the Teensy 3.1. A few guys have got it working with other Arduino variants so it is possible. 

Philippe Rolland

unread,
Nov 9, 2015, 9:10:40 AM11/9/15
to Flir Lepton
Dear Mike,
thanks for your message. what kind of problem have you in order to work Lepton on Teensy ?
Best regards.

Philippe Rolland

unread,
Nov 9, 2015, 9:15:26 AM11/9/15
to Flir Lepton
Message has been deleted

Max Ritter

unread,
Nov 9, 2015, 4:03:19 PM11/9/15
to Flir Lepton
Try my own implementation, works very stable with the Teensy 3.2:

/* Variables */
//Array to store one Lepton frame
byte leptonFrame[164];
//Array to store 80 x 60 RAW14 pixels
uint16_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();
}


Philippe Rolland

unread,
Nov 9, 2015, 4:28:36 PM11/9/15
to Flir Lepton
Dear Max,
thanks a lot ! it's very generous, great fun.
it's seems to me your code is in C; not compatible  Arduino sketches ? I'm wrong ?
A newby question: there is a difference of stability betweeen C and Arduino sketches ?
I must be use Xbee library for my project and I'm usually use Arduino library: do you know if it's difficult to convert in arduino sketch your implementation ?
Best regards

Max Ritter

unread,
Nov 10, 2015, 3:28:09 AM11/10/15
to Flir Lepton
Dear Philippe,

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).

Mike McRoberts

unread,
Nov 10, 2015, 9:41:07 AM11/10/15
to Flir Lepton
DigitalWriteFast isn't recognised for me. Is this a library? 

Max Ritter

unread,
Nov 10, 2015, 1:43:37 PM11/10/15
to Flir Lepton
You will be fine using digitalWrite instead ;) 

Philippe Rolland

unread,
Nov 11, 2015, 9:30:14 AM11/11/15
to Flir Lepton
Dear Max
I would really like to thank you for your generosity and your past to help me. Thank you so much.
Philippe.

Mike McRoberts

unread,
Nov 11, 2015, 9:57:29 AM11/11/15
to Flir Lepton
Thanks Max. I've not had a chance to try any of this on the Teensy yet but I will over the next week.

Mike McRoberts

unread,
Nov 11, 2015, 1:23:54 PM11/11/15
to Flir Lepton
Max....

error: 'segment' was not declared in this scope


Max Ritter

unread,
Nov 11, 2015, 6:37:19 PM11/11/15
to Flir Lepton
My mistake, the code was already prepared for the Lepton 3 sensor (which has 4 segments of 80x60 pixels per frame) and I manually removed that stuff not to confuse people.

So you may remove the segment from argument list or just set it to zero.

Message has been deleted

Philippe Rolland

unread,
Nov 29, 2015, 12:54:41 PM11/29/15
to Flir Lepton
Dear Max,
I don'y anderstand why result is always equal to 0 ?
#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
();
}



Do you know why ?
Best regards.

IMG_1269.JPG

Max Ritter

unread,
Nov 30, 2015, 8:02:06 AM11/30/15
to Flir Lepton
@Philippe Roland: Maybe this is because you have not set the CS pin to OUTPUT in the setup part. I also missed this in my example, sorry for that ! Also take care not to output single frames from the image on the serial port, as this will break the sync with the Lepton. It's better to print the whole raw values array after a complete image has been received. I did so in this updated sketch:

#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);
}

/* 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();
}

/* Print out the 80 x 60 raw values array for every complete image */
void printValues(){
  for(int i=0;i<60;i++){
    for(int j=0;j<80;j++){
      Serial.print(rawValues[(i*80) + j]);
      Serial.print(" ");
    }
    Serial.println();

Philippe Rolland

unread,
Nov 30, 2015, 11:33:25 AM11/30/15
to Flir Lepton

Dear Max
I'm very sorry sorry, but the following code give no result. I'm trying by Raspberry it's ok; so it's not some hardware problem.
But I'm using a shield teensy to include teensy 3.2 : https://www.sparkfun.com/products/13288
May be problem occured from the pin used ?

With your recommendation, Code now is:
#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();
}

It seem to me never Printvalues are executed ???
Strange ?
DO you know why ?
Problem with pin connexion ?
Thanks a lot for your help max,
Philippe.


Philippe Rolland

unread,
Nov 30, 2015, 11:36:39 AM11/30/15
to Flir Lepton
Dear max
I'm forgotten to say, I'm using only usb connector to powered teensy and shield, may be it's the problem ?
in order to work without shield do you know the direct connexion between teensy 3.2 and lepton ? without shield ?
I' don't find mosi/miso pin for example in teensy 3.2 (I'm founding on 3.1, not 3.2)
Philippe.

lazybeastz182

unread,
Jul 27, 2016, 6:30:02 PM7/27/16
to Flir Lepton
Thanks your code worked perfectly on my Teensy 3.2 Max.
Reply all
Reply to author
Forward
0 new messages