From 1cbbc97f13b4097f0e760c6c298bcf83b32131d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=93=96=E5=8D=9A?= <11038715+zhao_chengbo@user.noreply.gitee.com> Date: Thu, 26 May 2022 13:22:56 +0000 Subject: [PATCH] update demo/i2c/main.lua. Add AHT10 --- demo/i2c/main.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/demo/i2c/main.lua b/demo/i2c/main.lua index 15e1ac3..cf899dc 100644 --- a/demo/i2c/main.lua +++ b/demo/i2c/main.lua @@ -6,10 +6,11 @@ local sys = require "sys" --7bit地址,不包含最后一位读写位 local addr = 0x70 +-- AHT10:local addr = 0x38 -- 按照实际芯片更改编号哦 local i2cid = 0 --- 示例使用shtc3 +-- SHTC3 sys.taskInit( function() log.info("i2c.init", i2c.setup(0)) @@ -29,6 +30,26 @@ sys.taskInit( end ) +-- AHT10 +--sys.taskInit( +-- function() +-- log.info("i2c.init", i2c.setup(0)) +-- while true do +-- i2c.send(i2cid, addr, string.char(0xAC, 0x22, 0x00)) +-- sys.wait(100) +-- local data = i2c.recv(i2cid, addr, 6) +-- log.info("i2cdata", #data, data:toHex()) +-- local _, _, data2, data3, data4, data5, data6 = pack.unpack(data, "b6") +-- local hum = bit.bor(bit.bor(bit.lshift(data2, 12), bit.lshift(data3, 4)), bit.rshift(data4, 4))/ 1048576 * 10000 +-- log.info("hum", hum/100 ) +-- local tmp = bit.bor(bit.bor(bit.lshift(bit.band(data4, 0x0f), 16), bit.lshift(data5, 8)), data6) / 1048576 * 20000 - 5000 +-- log.info("tmp", tmp/100) +-- sys.wait(1000) +-- end +-- end +--) + + -- 用户代码已结束--------------------------------------------- -- 结尾总是这一句 sys.run() -- Gitee