Arduino Wiring and Example
- Connect board VIN (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead.
- Connect board GND (black wire) to Arduino GND
- Connect board SCL (yellow wire) to Arduino SCL
- Connect board SDA (blue wire) to Arduino SDA
The final results should resemble the illustration above, showing an Adafruit Metro development board.
Load Example
Open up File -> Examples -> Adafruit MLX90640 -> MLX90640_simpletest and upload to your Arduino wired up to the sensor.
Once you upload the code and open the Serial Monitor (Tools->Serial Monitor) at 115200 baud, you will see an ASCII representation of the thermal camera printed. You should see something similar to this:
Point the thermal camera at objects of differing temperatures to see the ASCII image change!
You also have the option to see the temperatures printed out in a grid. Change the lines below // uncomment *one* of the below to comment out the ASCIIART line and uncomment the TEMPERATURES line so that they match below:
// uncomment *one* of the below #define PRINT_TEMPERATURES //#define PRINT_ASCIIART
Upload the code and open the Serial Monitor (Tools->Serial Monitor) at 115200 baud, and you will see a grid of temperatures in Celsius printed. To fit the entire grid, you may need to resize the serial monitor window.
Point the thermal camera at objects of differing temperatures to see the printed temperatures change.
#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");
if (! mlx.begin(MLX90640_I2CADDR_DEFAULT, &Wire)) {
Serial.println("MLX90640 not found!");
while (1) delay(10);
}
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.print("Ambient temperature = ");
Serial.print(mlx.getTa(false)); // false = no new frame capture
Serial.println(" degC");
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();
}
}
Page last edited
Text editor powered by tinymce.