Working on Qwiic IR Array (MLX90640). Running this code:
What I am trying to do is, read temperature value from each pixel and if temperature value from any of the 768 pixel is above 27 (even if one pixel is above 27) turn LED on, otherwise keep it off. For this i have edited the code starting from line 72 as follows:
But this code is not keeping LED on though i am getting many values above 27 degree C on serial monitor. It turns LED on only when temperature gets above 30C and not otherwise. Please help with what is wrong here? and what is better logic. How make the code to check for all x between 0 to 768, if anything is above 27 C?
Working on Qwiic IR Array (MLX90640). Running this code:
What I am trying to do is, read temperature value from each pixel and if temperature value from any of the 768 pixel is above 27 (even if one pixel is above 27) turn LED on, otherwise keep it off. For this i have edited the code starting from line 72 as follows:
But this code is not keeping LED on though i am getting many values above 27 degree C on serial monitor. It turns LED on only when temperature gets above 30C and not otherwise. Please help with what is wrong here? and what is better logic. How make the code to check for all x between 0 to 768, if anything is above 27 C?
The expression "x < 768" is a boolean expression whith a value of 0 (false) or 1 (true). Are you sure you want to check to see if pixel 0 or pixel 1 is greater than or equal to 27?!?
byte led_state = LOW;
for (int x = 0 ; x < 768 ; x++) //NEWWWWWWWWWWWWWWWW
{
Serial.print("Pixel ");
Serial.print(x);
Serial.print(": ");
Serial.print(mlx90640To[x], 2);
Serial.print("C");
Serial.println();
if(mlx90640To[x] >= 27)
{
led_state = HIGH; // If any are >= 27, turn on the LED
break; // Once you find one over temperature, no need to look at the rest
}
}
digitalWrite(ledPin, led_state); //NEWWWWWWWWWWWWWWWWWWWW
I want to look at all 768 pixels and from there check if any value/values are above 27. If there is any (even if one pixel is giving 27C or above value) turn LED on, for all values below 27 keep LED off.
for (int x = 0 ; x < 768 ; x++) //NEWWWWWWWWWWWWWWWW
{
Serial.print("Pixel ");
Serial.print(x);
Serial.print(": ");
Serial.print(mlx90640To[x], 2);
Serial.print("C");
Serial.println();
if(mlx90640To[x] >= 27)
{
led_state = HIGH; // If any are >= 27, turn on the LED
break; // Once you find one over temperature, no need to look at the rest
}
}
digitalWrite(ledPin, led_state); //NEWWWWWWWWWWWWWWWWWWWW
This makes sense, but it is only giving me Pixel 0 values on serial monitor and LED is constantly ON. what is missing here?
Tried this, but same problem. It is not checking all 768 pixel values to know if there any above 27 or less.
I want the led to be turned on if there is at least one element higher than or equal to 27.
hnaimas:
Tried this, but same problem. It is not checking all 768 pixel values to know if there any above 27 or less.
I want the led to be turned on if there is at least one element higher than or equal to 27.
Show your new code and we can tell you where you or I made a mistake. It would also help to see the Serial Monitor output. You can copy and paste from the Serial Monitor.
include <Wire.h>
#include "MLX90640_API.h"
#include "MLX90640_I2C_Driver.h"
int ledPin = 13; //NEWWWWWWWWWWWWWWWW
int fan = 14; //NEW for FAN
const byte MLX90640_address = 0x33; //Default 7-bit unshifted address of the MLX90640
#define TA_SHIFT 8 //Default shift for MLX90640 in open air
static float mlx90640To[768];
paramsMLX90640 mlx90640;
void setup()
{
Wire.begin();
Wire.setClock(400000); //Increase I2C clock speed to 400kHz
pinMode(ledPin, OUTPUT); //NEWWWWWWWWWWWWWWW
pinMode(fan, OUTPUT); //NEWWWWWWWWWWWWWWW
Serial.begin(9600);
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);
}
Serial.println("MLX90640 online!");
//Get device parameters - We only have to do this once
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");
//Once params are extracted, we can release eeMLX90640 array
}
void loop()
{
for (byte x = 0 ; x < 2 ; x++) //Read both subpages
{
uint16_t mlx90640Frame[834];
int status = MLX90640_GetFrameData(MLX90640_address, mlx90640Frame);
if (status < 0)
{
Serial.print("GetFrame Error: ");
Serial.println(status);
}
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);
}
byte led_state = LOW;
digitalWrite(fan, LOW); //Fan Testing
for (int x = 0 ; x < 768 ; x++)
{
Serial.print("Pixel ");
Serial.print(x);
Serial.print(": ");
Serial.print(mlx90640To[x], 2);
Serial.print("C");
Serial.println();
if(mlx90640To[x] >= 27)
{
led_state = HIGH; // If any are >= 27, turn on the LED
digitalWrite(fan, HIGH); //Fan Testing
break; // Once you find one over temperature, no need to look at the rest
}
}
digitalWrite(ledPin, led_state);
//delay(1000);
}
//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);
}
There it is, i posted the images too. the output on the serial monitor starts with only pixel 0 for a long time and then gives random values.
johnwasser:
Show your new code and we can tell you where you or I made a mistake. It would also help to see the Serial Monitor output. You can copy and paste from the Serial Monitor.