6 @author Dozingfiretruck
9 local mlx90614 = require "mlx90614"
12 sys.taskInit(function()
13 -- 硬件i2c方式 618不支持此方式因为618发送会发送停止信号
16 print("i2c",i2c.setup(i2cid,i2c_speed))
18 -- 软件i2c 此方式通用,需要 2023.5.8之后编译的固件
19 --i2cid = i2c.createSoft(18,19)
23 print("mlx90614 ambient",mlx90614.ambient())
24 print("mlx90614 object",mlx90614.object())
32 local sys
= require
"sys"
35 local MLX90614_ADDRESS_ADR
= 0x5A
37 local MLX90614_TA
= 0x06
38 local MLX90614_TOBJ1
= 0x07
39 local MLX90614_TOBJ2
= 0x08
43 @api mlx90614.init(i2c_id)
44 @number 所在的i2c总线硬件/软件id
49 function mlx90614
.init(i2c_id
)
51 sys
.wait(20)--20 毫秒等待设备稳定
54 local rxbuff
= zbuff
.create(3)
58 @api mlx90614.ambient()
59 @return table mlx90614 环境温度
61 local mlx90614_ambient = mlx90614.ambient()
62 log.info("mlx90614_ambient", mlx90614_ambient)
64 function mlx90614
.ambient()
67 local ret
= i2c
.transfer(i2cid
, MLX90614_ADDRESS_ADR
, MLX90614_TA
, rxbuff
, 3)
69 ambient
= rxbuff
[0] |
(rxbuff
[1] << 8)
70 ambient
= ambient
*0.02 - 273.15
77 @api mlx90614.ambient()
78 @return table mlx90614 环境温度
80 local mlx90614_ambient = mlx90614.ambient()
81 log.info("mlx90614_ambient", mlx90614_ambient)
83 function mlx90614
.object()
86 local ret
= i2c
.transfer(i2cid
, MLX90614_ADDRESS_ADR
, MLX90614_TOBJ1
, rxbuff
, 3)
88 object
= rxbuff
[0] |
(rxbuff
[1] << 8)
89 object
= object
*0.02 - 273.15