mlx90614红外传感器
2021/10/7 6:12:56
本文主要是介绍mlx90614红外传感器,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
线接法 1
l vin ↔ 3V 物理引脚 1
l gnd ↔ gnd 物理引脚 6
l scl ↔ SCL.1 物理引脚 5
l sda ↔ SDA.1 物理引脚 3
线接法 2
MLX90614 Sensor |
Raspberry Pi |
VIN |
5V (Pin 2) |
GND |
GND (Pin 6) |
SCL |
GPIO 3 (Pin 5) |
SDA |
GPIO 2 (Pin 3) |
安装IIC库
sudo apt install i2c-tools
安装python的smbus
sudo apt install python-smbus
打开IIC
sudo raspi-config 选择
3. Interface options --5. I2C -- Enable --Yes
查看地址 i2cdetect -y -a 1
这里地址是 0x5a
近距离测试 , 此时 未用 补偿算法
获取数值
方法1
mlx90614.py
import smbus
from time import sleep
class MLX90614():
MLX90614_RAWIR1=0x04
MLX90614_RAWIR2=0x05
MLX90614_TA=0x06
MLX90614_TOBJ1=0x07
MLX90614_TOBJ2=0x08
MLX90614_TOMAX=0x20
MLX90614_TOMIN=0x21
MLX90614_PWMCTRL=0x22
MLX90614_TARANGE=0x23
MLX90614_EMISS=0x24
MLX90614_CONFIG=0x25
MLX90614_ADDR=0x0E
MLX90614_ID1=0x3C
MLX90614_ID2=0x3D
MLX90614_ID3=0x3E
MLX90614_ID4=0x3F
comm_retries = 5
comm_sleep_amount = 0.1
def __init__(self, address=0x5a, bus_num=1):
self.bus_num = bus_num
self.address = address
self.bus = smbus.SMBus(bus=bus_num)
def read_reg(self, reg_addr):
err = None
for i in range(self.comm_retries):
try:
return self.bus.read_word_data(self.address, reg_addr)
except IOError as e:
err = e
#"Rate limiting" - sleeping to prevent problems with sensor
#when requesting data too quickly
sleep(self.comm_sleep_amount)
#By this time, we made a couple requests and the sensor didn't respond
#(judging by the fact we haven't returned from this function yet)
#So let's just re-raise the last IOError we got
raise err
def data_to_temp(self, data):
temp = (data*0.02) - 273.15
return temp
def get_amb_temp(self):
data = self.read_reg(self.MLX90614_TA)
return self.data_to_temp(data)
def get_obj_temp(self):
data = self.read_reg(self.MLX90614_TOBJ1)
return self.data_to_temp(data)
if __name__ == "__main__":
sensor = MLX90614()
print(sensor.get_amb_temp())
print(sensor.get_obj_temp())
example.py
import time
from mlx90614 import MLX90614
thermometer_address = 0x5a
thermometer = MLX90614(thermometer_address)
while True:
print thermometer.get_amb_temp()
print thermometer.get_obj_temp()
time.sleep(1.5)
python2 example.py 即可获得数据
方法2
pip3 install adafruit-circuitpython-mlx90614
Read_data.py
import board
import adafruit_mlx90614
# The MLX90614 only works at the default I2C bus speed of 100kHz.
# A higher speed, such as 400kHz, will not work.
i2c = board.I2C()
mlx = adafruit_mlx90614.MLX90614(i2c)
# temperature results in celsius
print("Ambent Temp: ", mlx.ambient_temperature)
print("Object Temp: ", mlx.object_temperature)
调用 : python3 Read_data.py
这篇关于mlx90614红外传感器的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-10百万架构师第十三课:源码分析:Spring 源码分析:Spring核心IOC容器及依赖注入原理|JavaGuide
- 2025-01-10便捷好用的电商API工具合集
- 2025-01-09必试!帮 J 人团队解决物流错发漏发的软件神器!
- 2025-01-09不容小觑!助力 J 人物流客服安抚情绪的软件!
- 2025-01-09为什么医疗团队协作离不开智能文档工具?
- 2025-01-09惊叹:J 人团队用啥软件让物流服务快又准?
- 2025-01-09如何利用数据分析工具优化项目资源分配?4种工具推荐
- 2025-01-09多学科协作难?这款文档工具可以帮你省心省力
- 2025-01-09团队中的技术项目经理TPM:工作内容与资源优化策略
- 2025-01-09JIT生产管理法:优化流程,提升竞争力的秘诀