不到30行代码获取额温计测温结果

正值疫情肆虐,红外测温枪成了当前的紧俏货。本文用不到30行python代码获取红外测温传感器的室温值和目标温度值。

准备工作

  1. 支持Micropython运行的开发板,可以是pyboard 也可以是rtthread开发板上运行的micropython开发环境,如潘多拉开发板、W601开发板等等
  2. MLX9061X红外温度传感器,IIC接口
  3. vscode 开发环境或其他

MicroPython代码

我是用的是正点原子出的W601开发板,运行RTT的官方micropython固件,代码如下:

from machine import Pin, I2C
import time
# w601 iot board test
PIN_CLK = 66   # PB10
PIN_SDA = 65   # PB11
clk = Pin(("clk", PIN_CLK), Pin.OUT_OD)   # Select the PIN_CLK pin device as the clock
sda = Pin(("sda", PIN_SDA), Pin.OUT_OD)   # Select the PIN_SDA pin device as the data line
i2c = I2C(-1, clk, sda, freq=100000)
addr = 0x5a
while True:
    room = i2c.readfrom_mem(addr, 0x06, 2) 
    human = i2c.readfrom_mem(addr, 0x07, 2) 
    room = room[1]*256 + room[0]
    human = human[1]*256 + human[0]
    room*=2
    human*=2
    if room > 27315:
        room -= 27315
    else:
        room = 27315 - room
    if human > 27315:
        human -= 27315
    else:
        human = 27315 - human
    room/=100
    human/=100
    print("room: {room} human: {human} ".format(room = room , human = human) )
    time.sleep(0.5)

运行结果

当我变化手离传感器的距离时,明显看到human的值发生了变化,且和手离传感器的距离成正比,room的值基本不变。截取一段运行结果如下所示:

room: 28.15 human: 28.39 
room: 28.13 human: 33.07 
room: 28.09 human: 34.01 
room: 28.13 human: 34.15 
room: 28.09 human: 30.91 
room: 28.07 human: 29.09 
room: 28.09 human: 29.23 
room: 28.05 human: 32.75 
room: 28.07 human: 33.35 
room: 28.05 human: 26.85 
room: 28.11 human: 26.61 
room: 28.07 human: 28.97 
room: 27.99 human: 32.03 
room: 28.05 human: 28.97 
room: 28.01 human: 30.43 
room: 28.01 human: 32.59 
room: 28.05 human: 32.97 
room: 28.01 human: 31.63 
room: 28.01 human: 28.33 
room: 27.99 human: 28.05 
room: 27.99 human: 30.85 
room: 27.99 human: 32.25 
room: 27.95 human: 29.19 
room: 27.93 human: 26.55 
room: 27.97 human: 26.47 
room: 27.93 human: 26.49 
room: 27.89 human: 26.53 
room: 27.93 human: 26.59 
room: 27.87 human: 26.49 
room: 27.87 human: 26.55 
room: 27.87 human: 26.43 
room: 27.85 human: 26.59 
room: 27.87 human: 26.59 
room: 27.89 human: 26.47 
room: 27.81 human: 26.41 

最后,希望疫情早点过去,生活恢复如初。

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
MLX90614红外温度传感器_linux驱动源码,已经在产品中使用过。android 6.0 ,内核版本为3.4.39,可以做为你的学习设计参考。 #include <linux/kernel.h> #include <linux/module.h> #include <linux/miscdevice.h> #include <linux/moduleparam.h> #include <linux/delay.h> #include <linux/fs.h> #include <linux/timer.h> #include <linux/ioctl.h> #include <linux/gpio.h>//__gpio_set_value #include <mach/sys_config.h>//script_item_u #include <linux/pinctrl/consumer.h>//pin_config_set #include <linux/pinctrl/pinconf-sunxi.h>//SUNXI_PINCFG_TYPE_* #include <linux/io.h> #include <mach/sys_config.h> #include <mach/platform.h> #include <linux/slab.h> #define ACK 0 #define NACK 1 #define SA 0x5a //Slave address 单个MLX90614时地址为0x00,多个时地址默认为0x5a #define RAM_ACCESS 0x00 //RAM access command #define EEPROM_ACCESS 0x20 //EEPROM access command #define RAM_TOBJ1 0x07 //To1 address in the eeprom #define RAM_TOBJ2 0x08 #define RAM_TA 0x06 #define DEVICE_NAME "mlx90614" //struct gpio_config { // u32 gpio; /* gpio global index, must be unique */ // u32 mul_sel; /* multi sel val: 0 - input, 1 - output... */ // u32 pull; /* pull val: 0 - pull up/down disable, 1 - pull up... */ // u32 drv_level; /* driver level val: 0 - level 0, 1 - level 1... */ // u32 data; /* data val: 0 - low, 1 - high, only vaild when mul_sel is input/output */ //}; #define SCL_NAME "sensor_sck" #define SDA_NAME "sensor_sda" struct gpio_func_desc { unsigned short pin; char *name; }; struct gpio_func_desc SCLK ={0,SCL_NAME};//蓝色 struct gpio_func_desc SDIN ={0,SDA_NAME};//白色 struct gpio_config *sclk_gpio_p = NULL; struct gpio_config *sdin_gpio_p = NULL; void SMBus_StartBit(void); void SMBus_StopBit(void);

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值