Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save cyrusmeh/8b3636a8bbe54f8f193c8ce785e74710 to your computer and use it in GitHub Desktop.

Select an option

Save cyrusmeh/8b3636a8bbe54f8f193c8ce785e74710 to your computer and use it in GitHub Desktop.
In this exciting project, I demonstrate how to create a real thermal scanning camera using an Arduino Nano board, an AMG8833 thermal camera, and a 3.5-inch TFT LCD Module (SPI, 8 Pin).
#include <Wire.h>
#include <Adafruit_AMG88xx.h>
#include <SPI.h>
#include "Ucglib.h"
// Create an instance of the thermal camera
Adafruit_AMG88xx amg;
// Create an instance of the TFT display
Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 4, /*data=*/ 3, /*cd=*/ 6, /*cs=*/ 7, /*reset=*/ 5);
float maxTemperature = 0; // Variable to hold the maximum temperature
void setup() {
Serial.begin(9600);
// Initialize the thermal camera
if (!amg.begin()) {
Serial.println("Could not find a valid AMG8833 sensor, check wiring!");
while (1);
}
// Initialize the TFT display
ucg.begin(UCG_FONT_MODE_TRANSPARENT);
ucg.clearScreen();
}
void loop() {
// Read the thermal camera data
float pixels[64];
amg.readPixels(pixels);
// Clear the screen
ucg.clearScreen();
// Reset max temperature for the current loop
maxTemperature = 0;
// Display thermal data on the TFT
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
// Get the current pixel temperature
float currentTemp = pixels[y * 8 + x];
// Update max temperature if current temperature is higher
if (currentTemp > maxTemperature) {
maxTemperature = currentTemp;
}
// Map the temperature to a color (for example, blue to red)
uint8_t color = map(currentTemp, 20, 40, 0, 255); // Adjust the temperature range as needed
// Set the fill color
ucg.setColor(255 - color, 0, color); // Color gradient
// Draw a filled rectangle using drawBox
ucg.drawBox(x * 40, y * 60, 40, 60); // Adjust box size and position
ucg.setColor(255 - color, 0, color); // Set the fill color
ucg.drawBox(x * 40 + 1, y * 60 + 1, 38, 58); // Draw a smaller box for fill effect
}
}
// Display the maximum temperature on the screen
ucg.setColor(255, 255, 255); // Set text color to white
ucg.setPrintPos(10, 10); // Set position for the text
ucg.print("Max Temp: "); // Print label
ucg.print(maxTemperature); // Print maximum temperature
ucg.print(" C"); // Print unit
delay(500); // Update every half second
}
#include <Wire.h>
#include <Adafruit_AMG88xx.h>
#include <SPI.h>
#include "Ucglib.h"
// Create an instance of the thermal camera
Adafruit_AMG88xx amg;
// Create an instance of the TFT display
Ucglib_ILI9341_18x240x320_SWSPI ucg(/*sclk=*/ 4, /*data=*/ 3, /*cd=*/ 6, /*cs=*/ 7, /*reset=*/ 5);
float maxTemperature = 0; // Variable to hold the maximum temperature
void setup() {
Serial.begin(9600);
// Initialize the thermal camera
if (!amg.begin()) {
Serial.println("Could not find a valid AMG8833 sensor, check wiring!");
while (1);
}
// Initialize the TFT display
ucg.begin(UCG_FONT_MODE_TRANSPARENT);
ucg.clearScreen();
}
void loop() {
// Read the thermal camera data
float pixels[64];
amg.readPixels(pixels);
// Clear the screen
ucg.clearScreen();
// Reset max temperature for the current loop
maxTemperature = 0;
// Display thermal data on the TFT
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
// Get the current pixel temperature
float currentTemp = pixels[y * 8 + x];
// Update max temperature if current temperature is higher
if (currentTemp > maxTemperature) {
maxTemperature = currentTemp;
}
// Map the temperature to a color spectrum
uint8_t red, green, blue;
if (currentTemp <= -30) {
red = 0; green = 0; blue = 255; // Blue
} else if (currentTemp <= 0) {
red = 0; green = map(currentTemp, -30, 0, 0, 255); blue = 255; // Gradient from Blue to Cyan
} else if (currentTemp <= 100) {
red = map(currentTemp, 0, 100, 0, 255); green = 255; blue = 255; // Gradient from Cyan to Yellow
} else if (currentTemp <= 200) {
red = 255; green = map(currentTemp, 100, 200, 255, 0); blue = 0; // Gradient from Yellow to Red
} else if (currentTemp <= 300) {
red = 255; green = 0; blue = map(currentTemp, 200, 300, 0, 255); // Gradient from Red to Magenta
} else {
red = 255; green = map(currentTemp, 300, 400, 255, 0); blue = 255; // Gradient from Magenta to White
}
// Set the fill color
ucg.setColor(red, green, blue);
// Draw a filled rectangle using drawBox
ucg.drawBox(x * 40, y * 60, 40, 60); // Adjust box size and position
ucg.setColor(red, green, blue); // Set the fill color
ucg.drawBox(x * 40 + 1, y * 60 + 1, 38, 58); // Draw a smaller box for fill effect
}
}
// Display the maximum temperature on the screen
ucg.setColor(255, 255, 255); // Set text color to white
ucg.setPrintPos(10, 10); // Set position for the text
ucg.print("Max Temp: "); // Print label
ucg.print(maxTemperature); // Print maximum temperature
ucg.print(" C"); // Print unit
delay(500); // Update every half second
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment