本站改版新增arduino频道
Micropython ESP32 C3连接LU90614人体红外测温模块
一、目的

这一节我们来学习如何使用合宙ESP32 C3,连接LU90614人体红外测温模块,连接128x64点阵屏模块SPI接口液晶屏,进行温度显示实验。
二、环境
ESP32 C3开发板(MicroPython v1.19.1 on 2022-06-18)+LU90614人体红外测温模块 + 128x64点阵屏模块SPI接口液晶屏 + 几根杜邦线 + Win10商业版
ESP32 C3和各模块接线方法:


————————————————
from machine import Pin,SPI,PWM,UART
from st7567 import ST7567
from ufount1 import BMFont
import time
'''
1,体温模式发送指令:0XFA 0XC5 0XBF;2, 物温模式发送指令:0XFA 0XC6 0XC0;3,开始测温并上传温度指令 0XFA 0XCA 0XC4;
串口国际96081模式
'''
# 创建UART串口对象
uart = UART(1,baudrate = 9600,tx = 0, rx =1)
# 导入字库文件
font = BMFont("fonts/unifont-14-12888-16.v3.bmf")
# 创建SPI对象
spi = SPI(1,baudrate = 40_000_000,sck = Pin(2),mosi = Pin(3),miso = None)
# 定义屏幕背光参数
blk = PWM(Pin(8),duty = (0),freq = (1000))
# 创建LCD屏幕对象。# invX内容反转,0x00或0x01 # invY显示反转,True或False
lcd = ST7567(spi,dc = Pin(10,Pin.OUT),cs = Pin(7,Pin.OUT),rst = Pin(6,Pin.OUT),invX=0x00,invY=True,invdisp=0x00)
# 定义LED灯
led = Pin(12,Pin.OUT)
# 指令
Tiwen = bytearray(b'\xfa\xc5\xbf\r') #体温指令
Wuwen = bytearray(b'\xfa\xc6\xc0\r') #物温指令
Celian = bytearray(b'\xfa\xca\xc4\r') #开始测量
Data = bytearray(9) #数据缓存区
# 温度模块函数
def LU90614(mode):
if mode:
uart.write(Tiwen) # 串口写入指定命令
else:
uart.write(Wuwen)
# 写入串口数据
uart.write(Celian)
# 读取串口数据
Data = uart.read()
# 屏蔽空值
if Data != None:
if Data[1] == 0XAC:
# 在屏幕上显示体温
font.text(lcd,"体温:",0,32,color=1,font_size=16,reverse=False,clear=False,show=True,half_char=True,auto_wrap=True)
#print("体温:")
elif Data[1] == 0XAA:
# 在屏幕上显示物温
font.text(lcd,"物温:",0,32,color=1,font_size=16,reverse=False,clear=False,show=True,half_char=True,auto_wrap=True)
# print("物温:")
# 屏蔽不该显示的大额数值
if Data[2] and Data[3] != 255:
# 在屏幕上显示数值和温度符号
font.text(lcd,"%d.%d℃"%(Data[2],Data[3]),48,32,color=1,font_size=16,reverse=False,clear=False,show=True,half_char=True,auto_wrap=True)
#print("%d.%d℃"%(Data[2],Data[3]))
else:
font.text(lcd,"wait" + str(' '),48,32,color=1,font_size=16,reverse=False,clear=False,show=True,half_char=True,auto_wrap=True)
# 获取体温数值
data = Data[2]
# 温度控制。
if data > 35 and data < 39:
led.value(1)
else:
led.value(0)
def main():
# 设置屏幕背光
num = 100
blk.duty(int(num/1000*1023))
# 显示中文
font.text(lcd,"红外温度测量",16,0,color=1,font_size=16,reverse=False,clear=False,show=True,half_char=True,auto_wrap=True)
lcd.hline(0,20,128,1)
lcd.show()
#True 人体温度采集,Fales 物体温度采集
while True:
LU90614(True)
if __name__ == "__main__":
main()
四、字库和屏幕驱动资料
Micropython ESP32 C3连接GM12864屏幕ST7576驱动IC芯片
版权声明:本文为CSDN博主「魔都飘雪」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhusongziye/article/details/130994501
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0095870494842529 seconds