diff --git a/demo/i2c/main.lua b/demo/i2c/main.lua index 15e1ac390e5cac94f4ac1db72eb5cd4849a8b21f..cf899dc7deb2090983c63f50e81f5ae9a6e31c41 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()