This circuit integrates a Seeed Studio XIAO ESP32C3 microcontroller with a GY-MCU90640 thermal camera, an ili9341 TFT display, and an SPI SD card module. The microcontroller reads thermal data from the GY-MCU90640 and displays it on the ili9341 TFT display. Additionally, the microcontroller can store data on the SPI SD card. The circuit is powered by the 3.3V and GND pins of the XIAO ESP32C3.
XIAO ESP32C3
GY-MCU90640
SPI SD Card
ili9341 TFT Display
Resistor (1k Ohms)
#include <Adafruit_MLX90640.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#if defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_UNOR4_MINIMA)
// For the breakout board, you can use any 2 or 3 pins.
// These pins will also work for the 1.8" TFT shield.
/* SPI pin definition for Arduino UNO R3 and R4
| ST7789 | PIN | R3 | R4 | Description |
|--------|------|------|--------|----------------------|
| SCL | D13 | SCK | RSPCKA | Serial clock |
| SDA | ~D11 | COPI | COPIA | Serial data input |
| RES | ~D9 | PB1 | P303 | Reset signal |
| DC | D8 | PB0 | P304 | Display data/command |
*/
#define TFT_CS 10
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
#define SPI_MODE SPI_MODE3 // SPI_MODE2 or SPI_MODE3
#elif defined(ARDUINO_XIAO_ESP32S3)
// Seeed Studio XIAO ESP32-S3
#define TFT_MOSI D10
#define TFT_MISO D9
#define TFT_SCLK D8
#define TFT_CS D2 // (-1) // dummy
#define TFT_RST D1 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC D0
#define SPI_MODE SPI_MODE3 // SPI_MODE3
#else
#warning "must specify board type"
#endif
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
#if 0
// 1.3 inch ... TFT_RST must be D9
#define DEVICE_WIDTH 240
#define DEVICE_HEIGHT 240
#define DEVICE_ORIGIN 2
#define PIXEL_SIZE 7
#define INVERT_DISPLAY true
#else
// 2.4 inch ... "RESET" on breakout board can be connected to "RESET" or +3.3V on UNO R4 instead of D9.
#define DEVICE_WIDTH 240
#define DEVICE_HEIGHT 320
#define DEVICE_ORIGIN 1
#define PIXEL_SIZE 7
#define INVERT_DISPLAY false
#endif
// Font size for setTextSize(2)
#define FONT_WIDTH 12 // [px] (Device coordinate system)
#define FONT_HEIGHT 16 // [px] (Device coordinate system)
#define ClearScreen() tft.fillScreen(ST77XX_BLACK)
Adafruit_MLX90640 mlx;
float frame[32*24]; // buffer for full frame of temperatures
//low range of the sensor (this will be blue on the screen)
#define MINTEMP 20
//high range of the sensor (this will be red on the screen)
#define MAXTEMP 35
//the colors we will be using