Array comparison

Hello,
I am using a IR camera to detect fire, I have a 24x32 array (768 elements) filled with the temp of each pixel from the camera. I am trying to compare each element from this array to a defined temp variable to see if any temp values in the array are above the defined temp variable and therefore there is a fire in the cameras view.
Thanks

Great! What is the programming question? Have you written code? If so, post it in code tags please.

I have the code to fill my 24x32 array with the temp values of each pixel from my camera. The programming question is I need to compare each element from this array to a predefined variable to see if any of the temp values in the array are above this predefined temp.

With a for loop that iterates 768 times.

Or until you find a pixel that exceeds your threshold.

chumlad:
I have the code

...but we don't

If you post code as described in the how to use this forum sticky the forum software will not mess it up.

If you use the IDE autoformat tool (ctrl-t or Tools, Auto Format) the code is easier to follow.

  for (int y = 0 ; y < 24 ; y++)
   {
     for (int x = 0; x < 32; x++)

somewhere in here would seem to me to be ideal.
768 iterations.

sorry, here it is

#include <Wire.h>

#include "MLX90640_API.h"
#include "MLX90640_I2C_Driver.h"

const byte MLX90640_address = 0x33; //Default 7-bit unshifted address of the MLX90640

#define TA_SHIFT 8 //Default shift for MLX90640 in open air 

/////////////////
int ImageArray[24][32]={0};

float mlx90640To[768];
float Arrayout[768];
paramsMLX90640 mlx90640;

const byte calcStart = 33; //Pin that goes high/low when calculations are complete
//This makes the timing visible on the logic analyzer

void setup()
{
  pinMode(calcStart, OUTPUT);

  Wire.begin();
  Wire.setClock(400000); //Increase I2C clock speed to 400kHz

  Serial.begin(115200); //Fast serial as possible

  while (!Serial); //Wait for user to open terminal
  //Serial.println("MLX90640 IR Array Example");

  if (isConnected() == false)
  {
    Serial.println("MLX90640 not detected at default I2C address. Please check wiring. Freezing.");
    while (1);
  }

  int status;
  uint16_t eeMLX90640[832];
  status = MLX90640_DumpEE(MLX90640_address, eeMLX90640);
  if (status != 0)
    Serial.println("Failed to load system parameters");

  status = MLX90640_ExtractParameters(eeMLX90640, &mlx90640);
  if (status != 0)
    Serial.println("Parameter extraction failed");


  MLX90640_SetRefreshRate(MLX90640_address, 0x04); //Set rate to 4Hz effective - Works

  Wire.setClock(1000000); //Teensy will now run I2C at 800kHz (because of clock division)
}

void loop()
{
  long startTime = millis();
  for (byte x = 0 ; x < 2 ; x++)
  {
    uint16_t mlx90640Frame[834];
    int status = MLX90640_GetFrameData(MLX90640_address, mlx90640Frame);

    digitalWrite(calcStart, HIGH);
    float vdd = MLX90640_GetVdd(mlx90640Frame, &mlx90640);
    float Ta = MLX90640_GetTa(mlx90640Frame, &mlx90640);

    float tr = Ta - TA_SHIFT; //Reflected temperature based on the sensor ambient temperature
    float emissivity = 0.95;

    MLX90640_CalculateTo(mlx90640Frame, &mlx90640, emissivity, tr, mlx90640To);
    digitalWrite(calcStart, LOW);
    //Calculation time on a Teensy 3.5 is 71ms
  }
  long stopReadTime = millis();
  

  int z = 0;
  for (int y = 0 ; y < 24 ; y++)
   {
     for (int x = 0; x < 32; x++)
         {
           ImageArray[y][x] = mlx90640To[z++]; 
          
           Serial.print(ImageArray[y][x]);
           Serial.print(" "); 
          }
         
           Serial.println();
  }
     long stopPrintTime = millis();
   Serial.println();
   Serial.println();
   Serial.println();
   Serial.print("Read rate: ");
   Serial.print( 1000.0 / (stopReadTime - startTime), 2);
   Serial.println(" Hz");
   Serial.print("Read plus print rate: ");
   Serial.print( 1000.0 / (stopPrintTime - startTime), 2);
   Serial.println(" Hz");

}






//Returns true if the MLX90640 is detected on the I2C bus
boolean isConnected()
{
  Wire.beginTransmission((uint8_t)MLX90640_address);
  if (Wire.endTransmission() != 0)
    return (false); //Sensor did not ACK
  return (true);
}

chumlad:
I am using a IR camera to detect fire

Which Arduino?

chumlad:
I am trying to compare each element from this array to a defined temp variable

Could defined temp variable be in PROGMEM? Two 768 length float arrays is 6K.

Presumably a single threshold, not a per element value?

Set a flag 'foundFire' to false
For each of 768 elements,
if the element > fire threshold, set 'foundFire' to true

Go for coffee break.

aarg:
Go for coffee break.

:smiley:

I have similar software running of an ESP32 with 240x135 TFT display - it manages about 8Hz display rate, but I’m looking to optimise the per-pixel calibration in the example code.

@dougp looks like he's using a teensy.

Why bother with the array at all?

When your looping through to fill the array, just check the temp of the pixel you have right there and exit of you find a "hot" one.

-jim lee

jimLee:
When your looping through to fill the array, just check the temp of the pixel you have right there and exit of you find a "hot" one.
-jim lee

Bing. We have a winner.

aarg:
Bing. We have a winner.

Also reply #3