Hier nochmals der Code:
/*
Thermokamara mit Adafruit MLX90640 - IR Sensor 24 x 32 Pixel
K.Schneeberger 19.08.2022
ESP8266 NodeMCU
Adafruit MLX90640
2,8 Zoll Display ILI9341
MLX90640 NodeMCU
SCL 20 D1
SDA 19 D2
*/
//#define I2C_SDA 19
//#define I2C_SCL 20
#include <Adafruit_MLX90640.h>
#include <wire.h>
#include <Adafruit_GFX.h> // include Adafruit graphics library
#include <Adafruit_ILI9341.h> // include Adafruit ILI9341 TFT library
#define TFT_CS D0 // TFT CS pin is connected to NodeMCU pin D2 oder D0
#define TFT_RST D3 // TFT RST pin is connected to NodeMCU pin D3
#define TFT_DC D4 // TFT DC pin is connected to NodeMCU pin D4
// initialize ILI9341 TFT library with hardware SPI module
// SCK (CLK) ---> NodeMCU pin D5 (GPIO14)
// MOSI(DIN) ---> NodeMCU pin D7 (GPIO13)
#define TXSIZE 1 // Textgrösse 2 = 20 Pixel, 1 = 10 Pixel
#define TXINTER 20 // Intervall der Textausgabe
#define MINTEMP 20 // Minimale Temperatur (blau)
#define MAXTEMP 40 // Maximale Temperatur (rot)
#define ANZIRFA 150 // Anzahl der Farbwerte
Adafruit_MLX90640 mlx;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Farbtabelle
const uint16_t camColors[] = {
0x480F, 0x400F, 0x400F, 0x4010, 0x3810, 0x3010, 0x3010, 0x2810, 0x2010, 0x1810,
0x1811, 0x1011, 0x1011, 0x0811, 0x0011, 0x0031, 0x0051, 0x0072, 0x0092, 0x00B2,
0x00B2, 0x00D2, 0x00F2, 0x0112, 0x0132, 0x0152, 0x0172, 0x0192, 0x01B2, 0x01D2,
0x01F3, 0x0213, 0x0233, 0x0253, 0x0273, 0x0293, 0x02B3, 0x02D3, 0x02F3, 0x0313,
0x0333, 0x0353, 0x0373, 0x0394, 0x03B4, 0x03D4, 0x03F4, 0x0414, 0x0434, 0x0454,
0x0474, 0x0494, 0x04B4, 0x04D4, 0x04F4, 0x0514, 0x0534, 0x0554, 0x0574, 0x0590,
0x058F, 0x058F, 0x058E, 0x05AE, 0x05AD, 0x05AC, 0x05AB, 0x05CB, 0x05CA, 0x05CA,
0x05C9, 0x05C8, 0x05E8, 0x05E7, 0x05E6, 0x05E5, 0x0604, 0x0603, 0x0602, 0x0621,
0x0620, 0x0E20, 0x0E20, 0x0E40, 0x1640, 0x1E40, 0x2640, 0x2E40, 0x2E60, 0x3660,
0x3E60, 0x4E60, 0x4E80, 0x5680, 0x5E80, 0x6680, 0x6E80, 0x6EA0, 0x76A0, 0x7EA0,
0x8EC0, 0x96C0, 0xA6C0, 0xAEC0, 0xB6E0, 0xBEE0, 0xC6E0, 0xCEE0, 0xD6E0, 0xD700,
0xDEE0, 0xDEC0, 0xDEA0, 0xDE80, 0xE660, 0xE640, 0xE620, 0xE5E0, 0xE5C0, 0xE5A0,
0xE580, 0xE560, 0xE540, 0xE520, 0xE500, 0xE4E0, 0xE4C0, 0xE4A0, 0xE480, 0xEC40,
0xEC20, 0xEC00, 0xEBE0, 0xEBC0, 0xEBA0, 0xEB80, 0xEB60, 0xEB40, 0xEB20, 0xEB00,
0xEAE0, 0xEAC0, 0xEAA0, 0xEA80, 0xEA60, 0xEA40, 0xF200, 0xF1E0, 0xF1C0, 0xF1A0,
0xF180, 0xF160, 0xF140, 0xF100, 0xF0E0, 0xF0C0, 0xF0A0, 0xF090, 0xF060, 0xF020
};
float frame[32 * 24];
uint16_t displayPixelWidth, displayPixelHeight;
int j = 0; // Zähler
//-----------------------------------------------------
void setup() {
Serial.begin(9600);
delay(300);
if (!mlx.begin(MLX90640_I2CADDR_DEFAULT, &Wire)) {
Serial.println("Finde keinen MLX90640!");
while (1) delay(10);
}
Serial.println("Found Adafruit MLX90640");
//Wire.begin(I2C_SDA, I2C_SCL, 100000);
//mlx.setMode(MLX90640_INTERLEAVED);
mlx.setMode(MLX90640_CHESS);
mlx.setResolution(MLX90640_ADC_16BIT);
mlx.setRefreshRate(MLX90640_1_HZ);
//mlx.setMode(MLX90640_CHESS);
//mlx.setResolution(MLX90640_ADC_18BIT);
//mlx.setRefreshRate(MLX90640_8_HZ);
Wire.setClock(1000000); // max 1 MHz
tft.begin();
displayPixelWidth = tft.width() / 32;
displayPixelHeight = (tft.height() - 20) / 32;
//Serial.println("-- Thermal Camera Test --");
tft.setRotation(2);
tft.setTextWrap(true);
tft.setTextSize(TXSIZE);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(0, 145);
tft.print("Min");
tft.setCursor(26, 145);
tft.print(MINTEMP);
tft.setCursor(66, 145);
tft.print("Max");
tft.setCursor(90, 145);
tft.print(MAXTEMP);
delay(200);
}
//-----------------------------------------------------
void loop() {
int i;
float mint = 150.0, maxt = 0.0;
delay(500);
mlx.getFrame(frame);
for (uint8_t h = 0; h < 24; h++) {
for (uint8_t w = 0; w < 32; w++) {
float temp = frame[h * 32 + w]; // Temperatur holen
uint8_t colorIndex = map(temp, MINTEMP, MAXTEMP, 0, 255); // ?
colorIndex = (uint8_t)constrain((int16_t)colorIndex, (int16_t)0, (int16_t)ANZIRFA);
tft.fillRect(displayPixelWidth * w, displayPixelHeight * h,
displayPixelHeight, displayPixelWidth, camColors[colorIndex]);
if (temp > maxt) maxt = temp; // Extreme speichern
if (temp < mint) mint = temp;
}
}
j++;
if (j > TXINTER) {
tft.fillRect(0, 140, tft.width(), 37, 0x0000);
tft.setTextColor(ILI9341_YELLOW);
tft.setCursor(0, 145);
tft.print("Min");
tft.setCursor(26, 145);
tft.print(mint);
tft.setCursor(66, 145);
tft.print("Max");
tft.setCursor(90, 145);
tft.print(maxt);
j = 0;
delay(100);
}
}
//-----------------------------------------------------
Grüße