# MLX90614温度传感器 - HAL库驱动
**Repository Path**: jswyll_com/mlx90614
## Basic Information
- **Project Name**: MLX90614温度传感器 - HAL库驱动
- **Description**: 非接触红外温度传感器GY-90614型号与GY614615V3型号的HAL库驱动,支持硬件I2C、模拟I2C和UART的通信方式。
- **Primary Language**: C
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: https://jswyll.com/note/embed/mlx90614/
- **GVP Project**: No
## Statistics
- **Stars**: 3
- **Forks**: 2
- **Created**: 2022-06-26
- **Last Updated**: 2025-10-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 非接触红外温度传感器 - STM32HAL库驱动
[](https://www.apache.org/licenses/LICENSE-2.0) 
> 非接触红外温度传感器GY-90614型号与GY614615V3型号的HAL库驱动
>
> 本文原文:
## 快速开始
### 使用
1. 下载本工程
2. 使用STM32CubeMX配置I2C
3. 添加`mlx90614.c`和`mlx90614.h`到工程中
4. 调用
```c
#include "mlx90614.h"
int main()
{
mlx90614_init();
while(1)
{
float value;
if (mlx90614_read_temperature(&value))
{
printf("mlx90614 read temperature fail.\r\n");
}
else
{
printf("mlx90614 temperature: %.2f\r\n", value);
}
}
}
```
### 测试结果
| 模式 | 读取耗时 | 说明 |
| :-- | :-- | :-- |
| 硬件I2C | 565us | 最大稳定传输速率100000Hz |
| 模拟I2C | 1382us | 可自由选择SCL和SDA引脚 |
| UART | 115200bps时约1ms | 仅GY614615V3型号支持 |
#### GY-90614型号
- 每秒测量一次
```sh
mlx90614 temperature: 28.77
mlx90614 temperature: 28.83
mlx90614 temperature: 28.77
mlx90614 temperature: 28.77
mlx90614 temperature: 28.77
mlx90614 temperature: 28.83
mlx90614 temperature: 28.71
mlx90614 temperature: 28.75
mlx90614 temperature: 28.77
mlx90614 temperature: 28.79
mlx90614 temperature: 28.79
mlx90614 temperature: 28.85
mlx90614 temperature: 28.77
mlx90614 temperature: 28.77
mlx90614 temperature: 28.75
mlx90614 temperature: 28.71
mlx90614 temperature: 28.83
mlx90614 temperature: 28.85
```
- 每秒测量10次取平均值
```sh
mlx90614 temperature: 28.71
mlx90614 temperature: 28.77
mlx90614 temperature: 28.79
mlx90614 temperature: 28.79
mlx90614 temperature: 28.77
mlx90614 temperature: 28.79
mlx90614 temperature: 28.77
mlx90614 temperature: 28.65
mlx90614 temperature: 28.69
mlx90614 temperature: 28.69
mlx90614 temperature: 28.71
mlx90614 temperature: 28.71
mlx90614 temperature: 28.83
mlx90614 temperature: 28.80
mlx90614 temperature: 28.79
mlx90614 temperature: 28.77
```
#### GY614615V3型号
```sh
mlx90614 temperature: 28.10
mlx90614 temperature: 28.10
mlx90614 temperature: 28.10
mlx90614 temperature: 28.10
mlx90614 temperature: 28.10
mlx90614 temperature: 28.10
mlx90614 temperature: 28.14
mlx90614 temperature: 28.10
mlx90614 temperature: 28.10
mlx90614 temperature: 28.10
mlx90614 temperature: 28.10
mlx90614 temperature: 28.10
```
## 配置
### 硬件I2C
1. STM32CubeMX配置,选择其中一个I2C,然后切换为I2C模式,可在引脚图中切换使用的硬件I2C引脚,硬件连接使用配置的引脚

2. 修改`mlx90614.h`的宏定义
```c
#define MLX90614_USING_HARD_I2C 1
```
### 模拟I2C
> 参考`果果小师弟 - 基于STM32的MLX90614人体红外测温枪`[[1]](https://blog.csdn.net/qq_39400113/article/details/107099944 "果果小师弟 - 基于STM32的MLX90614人体红外测温枪")
1. STM32CubeMX配置,SCL和SDA引脚设置为GPIO_Output模式,User Label分别设置为`MLX90614_SCL`、`MLX90614_SDA`,**GPIO mode都设置为`Output Open Drain`**

2. 修改`mlx90614.h`的宏定义
```c
#define MLX90614_USING_HARD_I2C 0
```
### UART(仅GY614615V3型号)
PCB的ps焊点没焊上时为UART模式,模块的RC和TD引脚分别为模块串口的RXD、TXD引脚。
默认为自动上报模式,波特为9600bps,传输格式为raw模式。
初次配置,使用串口线连接模块
1. 发送`A4 06 03 01 AE`取消主动上报;
2. 发送`A4 06 01 06 B1`设置波特率为115200bps;
3. 发送`A4 06 05 55 04`将前面的更改断电保存
重新上电,之后发送`A4 03 07 07 B5`查询数据,返回数据的第7、8字节(从0数起)分别为环境温度的高低八位,结果除以100得到具体温度。
1. 在STM32CubeMX配置STM32与模块的串口;
2. 修改`mlx90614.h`的宏定义。打开UART模式并修改配置的HUART编号
```c
#define MLX90614_USING_UART 1
#define MLX90614_HUART huart2
```
### 打开调试打印
```c
#define MLX90614_USING_LOG 1
```
## 更新日志
### v1.1.1(2025.04.05)
- LICENSE切换为Apache 2.0
### v1.1.0(2021.06.27)
- 支持GY614615V3型号使用HAL库UART方式
### v1.0.0(2021.06.26)
- 支持使用HAL库I2C接口
- I2C模式支持硬件或模拟方式