MLX90640 Thermal Camera Help

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ceilowens
 
Posts: 13
Joined: Tue Sep 13, 2022 5:45 pm

MLX90640 Thermal Camera Help

Post by ceilowens »

Hello,

I'm using a MLX90640 Thermal Camera with an Arduino Mega. My goal is to showcase the thermal image on my computer and detect the highest thermal response. I'm not sure how to start. I've been researching and I would get instructions with using some other display called a Stemma Connector. I'm also reading I would have to download a multitude of libraries for my Thermal Camera to work, which I don't think I need to. I understand the pins and the connections with the Arduino.

Could someone help or direct me to some advice, even with some example code?

User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: MLX90640 Thermal Camera Help

Post by sj_remington »

The Adafruit tutorial is pretty complete, and helpful: https://learn.adafruit.com/adafruit-mlx ... mal-camera

I believe the "MLX_simpletest" example in the supplied Adafruit library will run on a Mega:

Code: Select all

#include <Adafruit_MLX90640.h>

Adafruit_MLX90640 mlx;
float frame[32*24]; // buffer for full frame of temperatures

// uncomment *one* of the below
//#define PRINT_TEMPERATURES
#define PRINT_ASCIIART

void setup() {
  while (!Serial) delay(10);
  Serial.begin(115200);
  delay(100);

  Serial.println("Adafruit MLX90640 Simple Test");
 while(! mlx.begin(MLX90640_I2CADDR_DEFAULT, &Wire)) {
    Serial.println("MLX90640 not found!");
  }
  Serial.println("Found Adafruit MLX90640");

  Serial.print("Serial number: ");
  Serial.print(mlx.serialNumber[0], HEX);
  Serial.print(mlx.serialNumber[1], HEX);
  Serial.println(mlx.serialNumber[2], HEX);
  
  //mlx.setMode(MLX90640_INTERLEAVED);
  mlx.setMode(MLX90640_CHESS);
  Serial.print("Current mode: ");
  if (mlx.getMode() == MLX90640_CHESS) {
    Serial.println("Chess");
  } else {
    Serial.println("Interleave");    
  }

  mlx.setResolution(MLX90640_ADC_18BIT);
  Serial.print("Current resolution: ");
  mlx90640_resolution_t res = mlx.getResolution();
  switch (res) {
    case MLX90640_ADC_16BIT: Serial.println("16 bit"); break;
    case MLX90640_ADC_17BIT: Serial.println("17 bit"); break;
    case MLX90640_ADC_18BIT: Serial.println("18 bit"); break;
    case MLX90640_ADC_19BIT: Serial.println("19 bit"); break;
  }

  mlx.setRefreshRate(MLX90640_2_HZ);
  Serial.print("Current frame rate: ");
  mlx90640_refreshrate_t rate = mlx.getRefreshRate();
  switch (rate) {
    case MLX90640_0_5_HZ: Serial.println("0.5 Hz"); break;
    case MLX90640_1_HZ: Serial.println("1 Hz"); break; 
    case MLX90640_2_HZ: Serial.println("2 Hz"); break;
    case MLX90640_4_HZ: Serial.println("4 Hz"); break;
    case MLX90640_8_HZ: Serial.println("8 Hz"); break;
    case MLX90640_16_HZ: Serial.println("16 Hz"); break;
    case MLX90640_32_HZ: Serial.println("32 Hz"); break;
    case MLX90640_64_HZ: Serial.println("64 Hz"); break;
  }
}

void loop() {
  delay(500);
  if (mlx.getFrame(frame) != 0) {
    Serial.println("Failed");
    return;
  }
  Serial.println();
  Serial.println();
  for (uint8_t h=0; h<24; h++) {
    for (uint8_t w=0; w<32; w++) {
      float t = frame[h*32 + w];
#ifdef PRINT_TEMPERATURES
      Serial.print(t, 1);
      Serial.print(", ");
#endif
#ifdef PRINT_ASCIIART
      char c = '&';
      if (t < 20) c = ' ';
      else if (t < 23) c = '.';
      else if (t < 25) c = '-';
      else if (t < 27) c = '*';
      else if (t < 29) c = '+';
      else if (t < 31) c = 'x';
      else if (t < 33) c = '%';
      else if (t < 35) c = '#';
      else if (t < 37) c = 'X';
      Serial.print(c);
#endif
    }
    Serial.println();
  }
}
Last edited by sj_remington on Tue Sep 13, 2022 6:07 pm, edited 1 time in total.

User avatar
ceilowens
 
Posts: 13
Joined: Tue Sep 13, 2022 5:45 pm

Re: MLX90640 Thermal Camera Help

Post by ceilowens »

It is pretty helpful, but it requires me to download a multitude of libraries and also purchase a screen. I want the output to at least showcase the thermal image on my computer. It would be a big plus if it showcased the highest index of heat.

User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: MLX90640 Thermal Camera Help

Post by sj_remington »

The simpletest example I just posted prints to the serial monitor.

User avatar
ceilowens
 
Posts: 13
Joined: Tue Sep 13, 2022 5:45 pm

Re: MLX90640 Thermal Camera Help

Post by ceilowens »

Do I have to download all the libraries incorporated into this?

User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: MLX90640 Thermal Camera Help

Post by sj_remington »

The only library you need to download is the Adafruit_MLX90640 library, which includes the example I mentioned.

User avatar
ceilowens
 
Posts: 13
Joined: Tue Sep 13, 2022 5:45 pm

Re: MLX90640 Thermal Camera Help

Post by ceilowens »

I'm trying in real time so bare with me, but every time I try to do it, I get multiple other libraries to download. For example, one library is for a touchscreen which I don't have/need. For what I'm trying to do, I want the output to display on my computer.

There's no code nor example I can reference wherever I look.
Attachments
thumbnail_Image.jpg
thumbnail_Image.jpg (312.38 KiB) Viewed 115 times

User avatar
sj_remington
 
Posts: 997
Joined: Mon Jul 27, 2020 4:51 pm

Re: MLX90640 Thermal Camera Help

Post by sj_remington »

Admittedly, Adafruit has succumbed to the "bloatware" philosophy of trying to protect the beginning user from having to understand any of the details of using their sensors. Here is how to run the "simpletest" example without downloading a bunch of unneeded libraries:

Remove all copies of the Adafruit_MLX90640 (or similarly named) library from your computer.

Go to this repository https://github.com/adafruit/Adafruit_MLX90640

Click the green "code" button and download the .zip file.

Open the .zip file and move the folder named "Adafruit_MLX90640-master" to your Arduino sketchbook "libraries" folder.

Open the Arduino IDE and under File>Examples>Adafruit_MLX90640 find the "simpletest" example. Run it.

Alternatively, use Sparkfun's no-nonsense library by following their tutorial at https://learn.sparkfun.com/tutorials/qw ... -guide/all

User avatar
ceilowens
 
Posts: 13
Joined: Tue Sep 13, 2022 5:45 pm

Re: MLX90640 Thermal Camera Help

Post by ceilowens »

I'm late, but thank you! I truly appreciate the help and insight.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”