I connected the thermo sensor to the Raspberry Pi and measured the temperature (Python)

Use

In a certain production, I decided to incorporate non-contact temperature measurement into the system, so I implemented it using Raspberry Pi + thermo sensor. It is not a handheld image, but a stationary image.

Equipment used

PC OS: macOS Catalina v10.15 Thermosensor: https://www.switch-science.com/catalog/3395/ Raspberry Pi 3B +: https://www.switch-science.com/catalog/3920/

Overview of thermosensor

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.

Preparation

Raspberry Pi environment construction

The explanation of Raspberry Pi setup and connection is omitted. It is assumed that the terminal can be used by SSH or display connection.

Nowadays, it seems that there is a tool for installing the OS on Raspberry Pi, so I think you should refer to the following article.

https://www.itmedia.co.jp/news/articles/2006/05/news031.html

I2C activation

terminal


sudo raspi-config

The CUI selection screen will appear, so It can be enabled with I2C-> enabled.

wiring

Use a breadboard. Reference

名称未設定.png

After wiring, execute the command to check if the connection is established.

terminal


i2cdetect -y 1

If there is 68, it is recognized correctly.

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Get temperature with Python

Installation of required modules

sudo pip3 install adafruit-circuitpython-amg88xx

Temperature measurement program

import time
import busio
import board
import adafruit_amg88xx

i2c_bus = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_amg88xx.AMG88XX(i2c_bus, addr=0x68)
time.sleep(0.5) #If you do not put a sleep, sensor.I can't get pixels
print(sensor.pixels)

When executed, a two-dimensional array will be returned.

terminal


sudo python3 test.py
[[23.5, 23.5, 24.25, 23.75, 23.25, 24.5, 24.25, 23.25], [23.0, 24.0, 23.5, 24.0, 23.75, 24.25, 24.5, 24.25], [23.75, 23.25, 23.75, 24.0, 23.75, 24.5, 24.5, 24.75], [23.25, 23.25, 23.25, 24.0, 23.5, 24.25, 24.5, 25.75], [23.5, 23.75, 23.75, 24.0, 23.5, 24.25, 24.0, 24.0], [23.75, 23.25, 24.25, 23.5, 23.75, 23.25, 23.75, 24.0], [23.25, 23.75, 23.5, 24.25, 23.75, 23.5, 24.0, 24.0], [23.5, 23.0, 24.0, 23.75, 23.25, 23.25, 24.75, 23.75]]

If you plot it in an easy-to-understand manner ...

import time
import busio
import board
import adafruit_amg88xx
import matplotlib.pyplot as plt

i2c_bus = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_amg88xx.AMG88XX(i2c_bus, addr=0x68)
time.sleep(0.5)
fig = plt.imshow(sensor.pixels, cmap="inferno")
plt.colorbar()
plt.savefig("plot.png ")

It's a face. You can get it like that.

asddwq.png

Implementation of temperature measurement

Since it is necessary to measure the temperature around the forehead, it is necessary to have the user fix the position of the face when measuring the temperature in a stationary state. Furthermore, ideally, it is good for UX when the temperature measurement starts when the face is aligned in place.

In order to realize these, I prepared a camera module separately and measured the temperature by using the detection that the face was in the specified position as a trigger. Ask the user to meet face to face by relying on the camera and frame shown on the display. Of course, when implementing this, it is necessary to fix the position of the camera and the relative position of the thermosensor.

Below is a sample program. Face detection used OpenCV. (The actual code is modified for the sample, and the operation has not been confirmed.)

import picamera
import picamera.array
import time
import cv2
import busio
import board
import adafruit_amg88xx

#Cascade file uses the one that is distributed
CascadeFile = "./haarcascade_frontalface_default.xml"

with picamera.PiCamera() as camera:
    #Camera settings
    camera.resolution = (400, 400)
    camera.rotation = 180
    camera.start_preview()
    time.sleep(2)

    with picamera.array.PiRGBArray(camera) as stream:
        while True:
            #Of the camera(50,50)From(350,350)Since the minimum size for face recognition and face recognition is 250x250, the recognition position and size can be narrowed down.
            camera.capture(stream, 'bgr', use_video_port=True)
            gray = cv2.cvtColor(stream.array[50:350, 50:350], cv2.COLOR_BGR2GRAY)
            cascade = cv2.CascadeClassifier(CascadeFile)
            face_list = cascade.detectMultiScale(gray, minSize=(250, 250), minNeighbors=3)

            if len(face_list) > 0:
                x, y, w, h = face_list[0]:
                temps = []
                i2c_bus = busio.I2C(board.SCL, board.SDA)
                sensor = adafruit_amg88xx.AMG88XX(i2c_bus, addr=0x68)

                #Temperature measurement 5 times
                for i in range(5):
                    time.sleep(0.3)
                    _max = 0
                    for j in sensor.pixels[2:6]:
                        for k in j[3:5]:
                            _max = max(_max, k) #Handle the maximum value in the range
                    temps.append(_max + 5) #Filling the gap between surface temperature and body temperature
                print(round(sum(sorted(temps)[1:4]) / 3, 1)) #Sort the temperature measurement results and output the average of the three
                break

            stream.seek(0)
            stream.truncate()
        camera.stop_preview()

There may be room for improvement in this part. (Determine this value based on the temperature, etc.)

temps.append(_max + 5) #Filling the gap between surface temperature and body temperature

It's hard to explain this code in detail, so check out around OpenCV`` PiCamera for more information.

Finally

It is a rough implementation by students in production, so please do not refer to it too much if certainty is required.

Thank you very much.

Recommended Posts

I connected the thermo sensor to the Raspberry Pi and measured the temperature (Python)
Use Raspberry Pi Python to TMP36 analog temperature sensor and MCP3008 AD converter
I tried using the DS18B20 temperature sensor with Raspberry Pi
The temperature is automatically measured using Raspberry Pi 3 and automatically uploaded to the server (Docker python3 + bottle + MySQL) for viewing!
I want to run the Python GUI when starting Raspberry Pi
Raspberry Pi --1 --First time (Connect a temperature sensor to display the temperature)
Read the data of the NFC reader connected to Raspberry Pi 3 with Python and send it to openFrameworks with OSC
I tweeted the illuminance of the room with Raspberry Pi, Arduino and optical sensor
Using the 1-Wire Digital Temperature Sensor DS18B20 from Python on a Raspberry Pi
How to use the Raspberry Pi relay module Python
Try using the temperature sensor (LM75B) on the Raspberry Pi.
I talked to Raspberry Pi
I want to prevent the speaker connected to the Raspberry Pi (jessie) from bouncing when the OS is restarted (Python script)
I want to know the features of Python and pip
I tried to enumerate the differences between java and python
I sent the data of Raspberry Pi to GCP (free)
[Raspberry Pi] Changed Python default to Python3
I tried to automate the watering of the planter with Raspberry Pi
[Introduction to Python] I compared the naming conventions of C # and Python.
Use python on Raspberry Pi 3 to illuminate the LED (Hello World)
About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi
I tried to estimate the pi stochastically
Detect temperature using python on Raspberry Pi 3!
Use BME280 temperature / humidity / barometric pressure sensor from Python on Raspberry Pi 2
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
Note: I want to do home automation with Home Assistant + Raspberry Pi + sensor # 1
Use python on Raspberry Pi 3 to light the LED with switch control!
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
The file name was bad in Python and I was addicted to import
I tried to verify and analyze the acceleration of Python by Cython
I measured the speed of list comprehension, for and while with python2.7.
I made an npm package to get the ID of the IC card with Raspberry Pi and PaSoRi
Connect to the console of Raspberry PI and display local IP and SD information
How to use Raspberry Pi pie camera Python
I tried L-Chika with Raspberry Pi 4 (Python edition)
[For beginners] I made a motion sensor with Raspberry Pi and notified LINE!
Sound the buzzer using python on Raspberry Pi 3!
Raspberry + am2302 Measure temperature and humidity with temperature and humidity sensor
Get temperature and humidity with DHT11 and Raspberry Pi
I want to get the file name, line number, and function name in Python 3.4
[Python] I will upload the FTP to the FTP server.
Try to use up the Raspberry Pi 2's 4-core CPU with Parallel Python
Use python on Raspberry Pi 3 and turn on the LED when it gets dark!
Connect to MySQL with Python on Raspberry Pi
I want to display the progress in Python!
Measure CPU temperature of Raspberry Pi with Python
Control music playback on a smartphone connected to Raspberry Pi 3 and bluetooth with AVRCP
When I tried to do socket communication with Raspberry Pi, the protocol was different
I tried to automate the article update of Livedoor blog with Python and selenium.
[Don't refer to 04.02.17] Display the temperature sensor on a real-time graph with rasberry pi 3.
I tried to compare the processing speed with dplyr of R and pandas of Python
I want to be notified of the connection environment when the Raspberry Pi connects to the network
Record temperature and humidity with systemd on Raspberry Pi
From setting up Raspberry Pi to installing Python environment
I tried to graph the packages installed in Python
Create a color sensor using a Raspberry Pi and a camera
Using the digital illuminance sensor TSL2561 with Raspberry Pi
Easy IoT to start with Raspberry Pi and MESH
I want to handle optimization with python and cplex
Try to visualize the room with Raspberry Pi, part 1
I tried to solve the soma cube with python