
MLX90640热成像传感器
简介
MLX90640热成像模块,包括原理图、硬件设计、工程测试等。
简介:MLX90640热成像模块,包括原理图、硬件设计、工程测试等。开源协议
:GPL 3.0
描述
MLX90640 热成像模块
MLX90640 是一款高分辨率红外热成像传感器,可与 Raspberry Pi 配合使用,实现实时温度可视化。通过 Python 脚本读取数据并显示热图,调整刷新率和插值优化图像。
3D渲染效果

硬件连接
| MLX90640 | RaspberryPi | Note |
|---|---|---|
| SDA | SDA (Pin3) | Serial Data |
| SCL | SCL (Pin5) | Serial Clock |
| GND | GND | Ground |
| VIN | 3V3 | Power |
示意图

实物图

环境搭建
创建并激活虚拟环境
python -m venv .venv
source .venv/bin/activate
安装所需软件包
pip install numpy
pip install matplotlib
pip install RPi.GPIO adafruit-blinka
pip install adafruit-circuitpython-mlx90640
连接测试
终端执行指令
sudo i2cdetect -y 1
显示 iic 设备地址为 0x33 对应设备为 MLX90640

通信测试
终端执行 mlx90640_print_temp.py 新建文件并添加如下代码
import time
import board
import busio
import numpy as np
import adafruit_mlx90640
def main():
# Setup I2C connection
i2c = busio.I2C(board.SCL, board.SDA, frequency=400000)
mlx = adafruit_mlx90640.MLX90640(i2c)
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_2_HZ
frame = np.zeros((24 * 32,)) # Initialize the array for all 768 temperature readings
while True:
try:
mlx.getFrame(frame) # Capture frame from MLX90640
average_temp_c = np.mean(frame)
average_temp_f = (average_temp_c * 9.0 / 5.0) + 32.0
print(f"Average MLX90640 Temperature: {average_temp_c:.1f}C ({average_temp_f:.1f}F)")
time.sleep(0.5) # Adjust this value based on how frequently you want updates
except ValueError as e:
print(f"Failed to read temperature, retrying. Error: {str(e)}")
time.sleep(0.5) # Wait a bit before retrying to avoid flooding with requests
except KeyboardInterrupt:
print("Exiting...")
break
except Exception as e:
print(f"An unexpected error occurred: {str(e)}")
if __name__ == "__main__":
main()
保存代码。
效果
终端执行指令 python mlx90640_print.py 运行代码

终端打印采集画面的平均温度,手掌靠近传感器,温度上升至体温。
图像显示
终端执行 touch mlx90640_plt.py 新建文件,添加如下代码
import time
import board
import busio
import numpy as np
import adafruit_mlx90640
import matplotlib.pyplot as plt
i2c = busio.I2C(board.SCL, board.SDA)
mlx = adafruit_mlx90640.MLX90640(i2c)
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_4_HZ # Set to a feasible refresh rate
plt.ion()
fig, ax = plt.subplots(figsize=(12, 7))
therm1 = ax.imshow(np.zeros((24, 32)), vmin=0, vmax=60)
cbar = fig.colorbar(therm1)
cbar.set_label(r'Temperature [$^{\circ}$C]', fontsize=14)
frame = np.zeros((24*32,))
t_array = []
max_retries = 5
while True:
t1 = time.monotonic()
retry_count = 0
while retry_count < max_retries:
try:
mlx.getFrame(frame)
data_array = np.reshape(frame, (24, 32))
therm1.set_data(np.fliplr(data_array))
therm1.set_clim(vmin=np.min(data_array), vmax=np.max(data_array))
fig.canvas.draw() # Redraw the figure to update the plot and colorbar
fig.canvas.flush_events()
plt.pause(0.001)
t_array.append(time.monotonic() - t1)
print('Sample Rate: {0:2.1f}fps'.format(len(t_array)/np.sum(t_array)))
break
except ValueError:
retry_count += 1
except RuntimeError as e:
retry_count += 1
if retry_count >= max_retries:
print(f"Failed after {max_retries} retries with error: {e}")
break
保存代码。
效果
终端执行指令 python mlx90640_plt.py 运行代码;

弹窗显示 matplotlib 伪彩图,调整摄像头位置,动态采集热成像画面;

优化平滑
为了优化画面显示效果,使用 Matplotlib 内置函数对数据进行平滑处理。

终端执行 touch mlx90640_plt_smooth.py 新建文件,添加如下代码
import time
import board
import busio
import numpy as np
import adafruit_mlx90640
import matplotlib.pyplot as plt
def initialize_sensor():
i2c = busio.I2C(board.SCL, board.SDA)
mlx = adafruit_mlx90640.MLX90640(i2c)
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_4_HZ
return mlx
def setup_plot():
plt.ion()
fig, ax = plt.subplots(figsize=(12, 7))
therm1 = ax.imshow(np.zeros((24, 32)), vmin=0, vmax=60, cmap='inferno', interpolation='bilinear')
cbar = fig.colorbar(therm1)
cbar.set_label(r'Temperature [°C]', fontsize=14)
plt.title('Thermal Image')
return fig, ax, therm1
def update_display(fig, ax, therm1, data_array):
therm1.set_data(np.fliplr(data_array))
therm1.set_clim(vmin=np.min(data_array), vmax=np.max(data_array))
ax.draw_artist(ax.patch)
ax.draw_artist(therm1)
fig.canvas.draw()
fig.canvas.flush_events()
def main():
mlx = initialize_sensor()
fig, ax, therm1 = setup_plot()
frame = np.zeros((24*32,))
t_array = []
max_retries = 5
while True:
t1 = time.monotonic()
retry_count = 0
while retry_count < max_retries:
try:
mlx.getFrame(frame)
data_array = np.reshape(frame, (24, 32))
update_display(fig, ax, therm1, data_array)
plt.pause(0.001)
t_array.append(time.monotonic() - t1)
print('Sample Rate: {0:2.1f}fps'.format(len(t_array) / np.sum(t_array)))
break
except ValueError:
retry_count += 1
except RuntimeError as e:
retry_count += 1
if retry_count >= max_retries:
print(f"Failed after {max_retries} retries with error: {e}")
break
if __name__ == '__main__':
main()
保存代码。
效果
终端执行指令 python mlx90640_plt_smooth.py 运行代码

画面清晰度相较于平滑处理前有较大提升。
参考:https://how2electronics.com/diy-thermal-imaging-camera-with-mlx90640-raspberry-pi/
设计图
未生成预览图,请在编辑器重新保存一次BOM
暂无BOM
克隆工程知识产权声明&复刻说明
本项目为开源硬件项目,其相关的知识产权归创作者所有。创作者在本平台上传该硬件项目仅供平台用户用于学习交流及研究,不包括任何商业性使用,请勿用于商业售卖或其他盈利性的用途;如您认为本项目涉嫌侵犯了您的相关权益,请点击上方“侵权投诉”按钮,我们将按照嘉立创《侵权投诉与申诉规则》进行处理。
请在进行项目复刻时自行验证电路的可行性,并自行辨别该项目是否对您适用。您对复刻项目的任何后果负责,无论何种情况,本平台将不对您在复刻项目时,遇到的任何因开源项目电路设计问题所导致的直接、间接等损害负责。










