オムロン MEMS非接触温度センサ D6T-44L-06の温度データを、I2C通信で取得します。
- 紹介編
- センサ編
- センサケース編
- Raspberry Pi編
- Python編
5.1 Form編
5.2 オムロン 非接触温度センサ D6T-44L-06編
5.3 Pololu 測距センサ VL53L0X編
5.4 BOSCH 温湿度・気圧センサ BME280
5.5 シャットダウン・再起動スイッチ編
5.6 OpenCV編
5.7 高速化編
Raspberry Pi上のPythonでI2Cを制御する為に、smbusモジュールを使用します。
smbusモジュールがインストールされていない場合、下記コマンドでインストールしてください。
pip install smbus
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
D6T-44L-06 script.
==================
Temperature measure 5 times/second.
Human-detectable distance: MAX 7[m]
5.0[V] I2C(0Ah)
4x4 array 5~45[deg]
***
2020/9/7
* Remake def pixels().
* Previous def result[0] is device temperature.
* Sometime temperature is 41degC over.
* Max temperature set 40degC.
"""
import threading
import time
import numpy as np
i2c_enable = False
try:
import smbus
i2c_enable = True
except:
i2c_enable = False
ADDRESS = 0x0a
REGISTER = 0x4c
class Sensor():
def __init__(self, *args, **kwargs):
self.avg_count = 10
self.enable = False
self._previous_result = None
self._shutdowning = False
self.temperature = 0.0
self.i2c_enable = i2c_enable
self._pixels_data = None
if self.i2c_enable:
self.enable = True
self._i2c = smbus.SMBus(1)
thread = threading.Thread(
name='D6T-44L-06_Measuring',
target=self.thread,
)
thread.daeom = True
thread.start()
@property
def array(self):
return (self.x, self.y)
def avg(self, pixels):
if self._pixels_data is None:
self._pixels_data = [pixels]
elif len(self._pixels_data) < self.avg_count:
self._pixels_data = np.append(
self._pixels_data, [pixels], axis=0)
elif len(self._pixels_data) == self.avg_count:
self._pixels_data = np.delete(
self._pixels_data, 0, axis=0)
self._pixels_data = np.append(
self._pixels_data, [pixels], axis=0)
def __del__(self):
self._shutdowning = True
@property
def high(self):
return 45.0
@property
def low(self):
return 5.0
@property
def name(self):
return 'D6T-44L-06'
@property
def pixels(self):
result = None
if self._pixels_data is not None:
result = np.average(self._pixels_data, axis=0)
return result
def stop(self):
self._shutdowning = True
def thread(self):
if self._shutdowning:
return
# for parent Thermo class.
result = None
if self.enable:
result = []
try:
data = self._i2c.read_i2c_block_data(
ADDRESS,
REGISTER,
32)
except:
self.i2c_enable = False
self.enable = False
return
self.temperature = (data[1]*256 + data[0]) / 10.0
data.pop(0)
data.pop(0)
if data[1] < 250 :
for i in range(4):
for j in range(4):
temperature \
= int((data[i*2*j+1])*256 + data[i*2*j]) / 10.0
if temperature > 41.0:
break
result.append(temperature)
if len(result) != 16:
result = self._previous_result
else:
self._previous_result = result
self.avg(result)
time.sleep(0.2)
thread = threading.Thread(
name='D6T-44L-06_Measuring',
target=self.thread,
)
thread.daeom = True
thread.start()
@property
def x(self):
return 4
@property
def y(self):
return 4
if __name__ == '__main__':
import time
sensor = Sensor()
while True:
tmp = sensor.pixels
if tmp is not None:
print(tmp)
#print(max(tmp), min(tmp))
time.sleep(1)
pass
YouTube: サーマルカメラ(サーモ AI デバイス TiD) Python編
web: サーモ AI デバイス TiD Python D6T編 (URLが変更されました)