Je ne sais pas pourquoi je n'arrive PAS à lire le premier capteur, bien que je l'ai changé, peut-être les longs câbles ?

This commit is contained in:
Christian Zufferey
2020-05-21 14:19:16 +02:00
parent 1024ce5a95
commit 76bda051a0
4 changed files with 50 additions and 7 deletions

View File

@@ -2,12 +2,12 @@
-- https://github.com/zuzu59/NodeMCU_Lua/tree/master/Mesures/humidity/bolo-thingspeak/docu/HTU21D.txt
function readHTU21D()
if verbose then print("\n 0_htu21d.lua zf200119.1517 \n") end
if verbose then print("\n 0_1_htu21d.lua zf200521.1404 \n") end
id = 0 sda = 5 scl = 6 addr = 0x40
HUMIDITY = 0xE5 TEMPERATURE = 0xE3
i2c.setup(id, sda, scl, i2c.SLOW) sda = nil scl = nil
function read_HTU21D(zreg, zdelay)
i2c.start(id) i2c.address(id, addr, i2c.TRANSMITTER)
i2c.write(id, zreg) i2c.stop(id)

View File

@@ -0,0 +1,43 @@
-- Lit le capteur I2C HTU21D de mesure d'humidité et de température
-- https://github.com/zuzu59/NodeMCU_Lua/tree/master/Mesures/humidity/bolo-thingspeak/docu/HTU21D.txt
function readHTU21D()
if verbose then print("\n 0_2_htu21d.lua zf200521.1347 \n") end
id = 0 sda = 4 scl = 6 addr = 0x40
HUMIDITY = 0xE5 TEMPERATURE = 0xE3
i2c.setup(id, sda, scl, i2c.SLOW) sda = nil scl = nil
function read_HTU21D(zreg, zdelay)
i2c.start(id) i2c.address(id, addr, i2c.TRANSMITTER)
i2c.write(id, zreg) i2c.stop(id)
i2c.start(id) i2c.address(id, addr, i2c.RECEIVER)
tmr.delay(zdelay)
r = i2c.read(id,3) i2c.stop(id)
return r
end
function readTemp()
r = read_HTU21D(TEMPERATURE, 50000)
r = (bit.band((bit.lshift(string.byte(r,1),8)+string.byte(r,2)),0xfffc)*17572)/65536-4685
return tonumber(string.format("%.1f", tostring(r/100)))
end
function readHumi()
r = read_HTU21D(HUMIDITY, 16000)
r = (bit.band((bit.lshift(string.byte(r,1),8)+string.byte(r,2)),0xfffc)*12500)/65536-600
return tonumber(string.format("%.1f", tostring(r/100)))
end
ztemp1=readTemp() zhum1=readHumi()
if verbose then print("Temperature: "..ztemp1.." °C") end
if verbose then print("Humidity: "..zhum1.." %") end
id=nil sda=nil scl=nil addr=nil HUMIDITY=nil TEMPERATURE=nil r=nil
read_HTU21D=nil readTemp=nil readHumi=nil readHTU21D=nil
if verbose then print(node.heap()) end
collectgarbage()
if verbose then print(node.heap()) end
end
readHTU21D()

View File

@@ -1,6 +1,6 @@
-- Scripts à charger après le boot pour démarrer son projet
print("\n boot.lua zf200303.1409 \n")
print("\n boot.lua zf200521.1339 \n")
function boot()
verbose = true
@@ -10,11 +10,11 @@ function boot()
--f="0_htu21d.lua" if file.exists(f) then dofile(f) end
--zurl=thingspeak_url.."field1="..tostring(ztemp1).."&field2="..tostring(zhum1)
--f="0_send_data.lua" if file.exists(f) then dofile(f) end
f="0_btn_flipflop.lua" if file.exists(f) then dofile(f) end
--f="0_btn_flipflop.lua" if file.exists(f) then dofile(f) end
f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end
f="0_cron.lua" if file.exists(f) then dofile(f) end
f="0_tst3_socat.lua" if file.exists(f) then dofile(f) end
--f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end
--f="0_cron.lua" if file.exists(f) then dofile(f) end
--f="0_tst3_socat.lua" if file.exists(f) then dofile(f) end
--f = "web_ide2.lua" if file.exists(f) then dofile(f) end
print("verbose:",verbose)