Real-time visualization of thermography AMG8833 data in Python

Introduction

This article is a record of using the 8x8 infrared array sensor "AMG8833" from Arduino, sending the data to a PC in real time and visualizing it with Python (PyQt5, PyQtGraph).

It is visualized in real time like the image below. amg8833.gif

Arduino Arduino acquires thermography data and sends it to a PC (Python) by serial communication. AMG8833 This time, I am using Switch Science's Conta ™ Thermography AMG8833 installed.

According to Switch Science

The temperature measurement range for each element is 0 ° C to 80 ° C. The measurement area is a square pyramid in front of the sensor (about 60 degrees vertically and horizontally), and a two-dimensional image obtained by dividing this area into 8x8 pixels can be obtained.

We also use Conta ™ Base Shield to make AMG8833 easy to use.

Data acquisition & transmission

There are several AMG8833 libraries listed on the Switch Science page, but here we are using SparkFun's SparkFun_GridEYE_Arduino_Library. The following program is just a slight change of Sample Program.

In serial communication, 8x8 = 64 temperature data are transmitted as character strings separated by ",".

amg8833-serial.ino


#include <SparkFun_GridEYE_Arduino_Library.h>
#include <Wire.h>

float pixelTable[64];

GridEYE grideye;

void setup() {
  Wire.begin();
  //The switch science AMG8833 address is set to 0x68 by default.
  grideye.begin(0x68);
  Serial.begin(115200);
}

void loop() {
  // 8x8=Obtain the temperature for 64 pixels and store it in grideye.
  for(unsigned char i = 0; i < 64; i++){
    pixelTable[i] = grideye.getPixelTemperature(i);
  }
  //The temperature of all pixels","Separated by and arranged in one line and transmitted by serial communication.
  for(unsigned char i = 0; i < 64; i++){
    Serial.print(pixelTable[i]);
    if(i != 63){
      Serial.print(",");
    }
  }
  Serial.println();
  delay(50);
}

Python The heat map is displayed in real time based on the temperature data received from Arduino.

Library

--pyserial --serial communication

Data visualization in Python is matplotlib, but it has the disadvantage that it is too heavy to update the screen in real time with matplotlib. Therefore, instead of matplotlib, we use a lightweight library called pyqtgraph.

However, this time, I am using a part of matpotlib to convert the temperature data to color (RGBA). It seems that pyqtgraph can be similar, but in that case it seems that you need to specify the color to be used for the color map. Here, we use matplotlib, which provides a color map by default.

Data reception & heat map display

heatmap.py


from pyqtgraph.Qt import QtGui, QtCore
import matplotlib.cm as cm
import matplotlib as mpl
import pyqtgraph as pg
import numpy as np
import serial

#TEMP to make the heatmap easier to see_MAX=40.Set to 0
TEMP_MIN = 0.0
TEMP_MAX = 40.0

app = QtGui.QApplication([])

win = pg.GraphicsLayoutWidget(show=True, title="AMG8833")
win.resize(600,600)
win.setWindowTitle('AMG8833')
pg.setConfigOptions(antialias=True)

view = win.addViewBox()
view.setAspectLocked(True)

img = pg.ImageItem(border='w')
view.addItem(img)

#Color Map for converting temperature to color
norm = mpl.colors.Normalize(vmin=TEMP_MIN, vmax=TEMP_MAX)
cmap = cm.jet
m = cm.ScalarMappable(norm=norm, cmap=cmap)

#Serial communication
ser = serial.Serial("COM13", 115200, timeout=1)

#8x8 temperature data
data = np.zeros((8, 8))

def get_data():
    global data, ser
    if ser.in_waiting:
        #Receive data from Arduino
        #Exception handling is easy because an error will occur when acquiring data.
        try:
            line = ser.readline().decode().strip()
            temps = [float(t) for t in line.split(",")]
            data = np.array(temps).reshape((8, 8))
        except:
            pass

def update_plot():
    global img, data
    img.setImage(m.to_rgba(data))

#Data reception every 50ms
timer1 = QtCore.QTimer()
timer1.timeout.connect(get_data)
timer1.setInterval(50)
timer1.start()

#Heatmap update every 100ms
timer2 = QtCore.QTimer()
timer2.timeout.connect(update_plot)
timer2.setInterval(100)
timer2.start()

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

In the above program, data reception and heatmap update are separated into different QTimers. If you update the heatmap every time you receive data, the heatmap may not be updated in time. To prevent this, data reception and heat map update can be performed separately.

Reference link

-Visualize AMG8833 data with a simple thermography browser (Part 1)

Recommended Posts

Real-time visualization of thermography AMG8833 data in Python
Power BI visualization of Salesforce data entirely in Python
Recommendation of Altair! Data visualization with Python
How to send a visualization image of data created in Python to Typetalk
The story of reading HSPICE data in Python
A well-prepared record of data analysis in Python
Summary of tools needed to analyze data in Python
Full-width and half-width processing of CSV data in Python
Not being aware of the contents of the data in python
List of Python code used in big data analysis
Let's use the open data of "Mamebus" in Python
Handle Ambient data in Python
Display UTM-30LX data in Python
Visualization of data by prefecture
Equivalence of objects in Python
Python application: data visualization # 2: matplotlib
Implementation of quicksort in Python
Try scraping the data of COVID-19 in Tokyo with Python
[Homology] Count the number of holes in data with Python
Comparison of data frame handling in Python (pandas), R, Pig
Get Leap Motion data in Python.
Pixel manipulation of images in Python
Read Protocol Buffers data in Python3
Get data from Quandl in Python
[ns3-30] Enable visualization of Python scripts
Division of timedelta in Python 2.7 series
Proper use of Python visualization packages
MySQL-automatic escape of parameters in python
Handle NetCDF format data in Python
Handling of JSON files in Python
Data visualization in Python-draw cool heatmaps
Implementation of life game in Python
Waveform display of audio in Python
Hashing data in R and Python
Easy data visualization with Python seaborn.
Law of large numbers in python
Implementation of original sorting in Python
Python application: data visualization part 1: basic
Reversible scrambling of integers in Python
Data analysis starting with python (data visualization 1)
Data analysis starting with python (data visualization 2)
A simple data analysis of Bitcoin provided by CoinMetrics in Python
Impressions of touching Dash, a data visualization tool made by python
[Python] Visualization of longitudinal data (plot, boxplot, violin plot, confidence interval, histogram)
[Blender Python] Arrange custom property data in template_list () of UI layout
General Theory of Relativity in Python: Introduction
Introduction to docker Create ubuntu environment in ubuntu
Real-time visualization of thermography AMG8833 data in Python
Put Python3 in Docker container of Amazon Linux2
Get additional data in LDAP with python
Conversion of string <-> date (date, datetime) in Python
Data input / output in Python (CSV, JSON)
Check the behavior of destructor in Python
Python Application: Data Visualization Part 3: Various Graphs
Python visualization tool for data analysis work
(Bad) practice of using this in Python
Ant book in python: Sec. 2-4, data structures
Output tree structure of files in Python
Try working with binary data in Python
Display a list of alphabets in Python 3
Comparison of Japanese conversion module in Python3
Summary of various for statements in Python
Get Google Fit API data in Python
The result of installing python in Anaconda