Enfin cela commence à bien fonctionner. Fait de l'ordre dans le code. Reste maintenant encore à envoyer les données dans la DB InfluxDB
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
-- Lit le capteur I2C HTU21D de mesure d'humidité et de température
|
||||
print("\n 0_get_data.lua zf191215.1329 \n")
|
||||
|
||||
-- https://cdn-shop.adafruit.com/datasheets/1899_HTU21D.pdf
|
||||
-- Comparaison DHT22, AM2302, AM2320, AM2321, SHT71, HTU21D, Si7021, BME280
|
||||
-- http://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html
|
||||
-- Il est compatible avec le capteur SI7021 mais pas avec la lib SI7021 du NodeMCU Lua :-(
|
||||
|
||||
-- source: https://github.com/famzah/nodemcu/tree/master/HTU21D-TLS
|
||||
-- source2: https://github.com/tebben/NodeMCU
|
||||
-- source3: https://github.com/codywon/NodeMCU-2
|
||||
|
||||
scl = 1
|
||||
sda = 2
|
||||
id = 0
|
||||
addr = 0x40
|
||||
HUMIDITY = 0xE5
|
||||
TEMPERATURE = 0xE3
|
||||
SOFTRESET = 0xFE
|
||||
|
||||
print(scl, sda, id, addr, HUMIDITY, TEMPERATURE, SOFTRESET)
|
||||
|
||||
zspeed = i2c.setup(id, sda, scl, 500000)
|
||||
print(zspeed)
|
||||
|
||||
i2c.start(id)
|
||||
zerr = i2c.address(id, addr, i2c.TRANSMITTER)
|
||||
i2c.stop(id)
|
||||
|
||||
print("ack: ",zerr)
|
||||
|
||||
|
||||
--[[
|
||||
|
||||
i2c.write(id, SOFTRESET)
|
||||
i2c.stop(id)
|
||||
|
||||
tmr.delay(20*1000)
|
||||
|
||||
|
||||
i2c.start(id)
|
||||
i2c.address(id, addr, i2c.TRANSMITTER)
|
||||
i2c.write(id, HUMIDITY)
|
||||
i2c.stop(id)
|
||||
|
||||
i2c.start(id)
|
||||
i2c.address(id, addr, i2c.RECEIVER)
|
||||
tmr.delay(50*1000)
|
||||
r = i2c.read(id,3)
|
||||
i2c.stop(id)
|
||||
|
||||
|
||||
print(string.byte(r))
|
||||
print(string.byte(r,2))
|
||||
print(string.byte(r,3))
|
||||
|
||||
]]
|
||||
@@ -1,59 +0,0 @@
|
||||
-- Lit le capteur I2C HTU21D de mesure d'humidité et de température
|
||||
print("\n 0_get_data.lua zf191216.1205 \n")
|
||||
|
||||
-- https://cdn-shop.adafruit.com/datasheets/1899_HTU21D.pdf
|
||||
-- Comparaison DHT22, AM2302, AM2320, AM2321, SHT71, HTU21D, Si7021, BME280
|
||||
-- http://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html
|
||||
-- Il est compatible avec le capteur SI7021 mais pas avec la lib SI7021 du NodeMCU Lua :-(
|
||||
|
||||
-- http://electromag1.wifeo.com/capteurs-de-temperature-et-humidite-gy-21-et-si7021.php
|
||||
-- source: https://github.com/famzah/nodemcu/tree/master/HTU21D-TLS
|
||||
-- source2: https://github.com/tebben/NodeMCU
|
||||
-- source3: https://github.com/codywon/NodeMCU-2
|
||||
|
||||
|
||||
id = 0
|
||||
sda = 5
|
||||
scl = 6
|
||||
addr = 0x40
|
||||
HUMIDITY = 0xE5
|
||||
TEMPERATURE = 0xE3
|
||||
|
||||
i2c.setup(id, sda, scl, i2c.SLOW)
|
||||
|
||||
i2c.start(id)
|
||||
i2c.address(id, addr, i2c.TRANSMITTER)
|
||||
i2c.write(id, HUMIDITY)
|
||||
i2c.stop(id)
|
||||
|
||||
i2c.start(id)
|
||||
i2c.address(id, addr, i2c.RECEIVER)
|
||||
tmr.delay(50*1000)
|
||||
|
||||
r = i2c.read(id,3)
|
||||
i2c.stop(id)
|
||||
|
||||
print(string.byte(r))
|
||||
print(string.byte(r,2))
|
||||
print(string.byte(r,3))
|
||||
|
||||
|
||||
|
||||
--i2c.address(id, addr, i2c.RECEIVER)
|
||||
|
||||
--[[
|
||||
i2c.stop(id)
|
||||
|
||||
|
||||
tmr.delay(17*1000)
|
||||
|
||||
|
||||
i2c.start(id)
|
||||
r = i2c.read(id,3)
|
||||
i2c.stop(id)
|
||||
|
||||
print(string.byte(r))
|
||||
print(string.byte(r,2))
|
||||
print(string.byte(r,3))
|
||||
]]
|
||||
|
||||
41
Mesures/humidity/bolo/0_htu21d.lua
Normal file
41
Mesures/humidity/bolo/0_htu21d.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
-- Lit le capteur I2C HTU21D de mesure d'humidité et de température
|
||||
print("\n 0_htu21d.lua zf191216.2115 \n")
|
||||
|
||||
-- module https://learn.sparkfun.com/tutorials/htu21d-humidity-sensor-hookup-guide/all
|
||||
-- schéma https://github.com/sparkfun/HTU21D_Breakout/blob/master/hardware/SparkFun_HTU21D_Breakout.pdf
|
||||
-- data sheet https://cdn.sparkfun.com/assets/6/a/8/e/f/525778d4757b7f50398b4567.pdf
|
||||
-- Comparaison DHT22, AM2302, AM2320, AM2321, SHT71, HTU21D, Si7021, BME280
|
||||
-- http://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html
|
||||
-- théorie http://electromag1.wifeo.com/capteurs-de-temperature-et-humidite-gy-21-et-si7021.php
|
||||
-- source lua: https://github.com/tebben/NodeMCU
|
||||
|
||||
-- ATTENTION: il n'y a seulement que certaines combinaisons de pins qui fonctionnent avec le capteur HTU21D avec le NodeMCU !
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
r = nil
|
||||
print("Temperature: "..readTemp().." °C")
|
||||
print("Humidity: "..readHumi().." %")
|
||||
@@ -30,21 +30,31 @@ Choses qui ne seraient pas possible si on l'avait fait en C++ (mode Arduino), co
|
||||
Toutes les fonctions sont bien séparées dans des scripts, cela *complexifie* le projet mais cela facilite la portabilité entre les projets et aussi sa mise au point.
|
||||
|
||||
|
||||
|
||||
## Astuces de mesures
|
||||
On utilise un tout petit capteur, le HTU21D, d'humidité et de température I2C. Il est vraiment très bon marché (1.5$), simple à utiliser et super précis.
|
||||
|
||||
https://learn.sparkfun.com/tutorials/htu21d-humidity-sensor-hookup-guide/all
|
||||
|
||||
Datasheet:
|
||||
|
||||
https://cdn.sparkfun.com/assets/6/a/8/e/f/525778d4757b7f50398b4567.pdf
|
||||
|
||||
On arrive à le souder directement sur le NodeMCU, ce qui nous permet de faire un point de mesure décentralisé pour moins de 5.-
|
||||
|
||||

|
||||
soudure du module HTU21D directement sur le NodeMCU_Lua
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Il faut *flasher* le NodeMCU avec ce firmware:
|
||||
|
||||
|
||||
https://github.com/zuzu59/NodeMCU_Lua/blob/master/Firmware/nodemcu-master-11-modules-2019-12-15-16-45-47-float.bin
|
||||
|
||||
Avec ces modules:
|
||||
|
||||
```
|
||||
adc file gpio http i2c mqtt net node ow rtctime si7021 sntp tmr uart wifi
|
||||
```
|
||||
bit,file,gpio,http,i2c,net,node,rtctime,tmr,uart,wifi
|
||||
```
|
||||
|
||||
|
||||
## Utilisation
|
||||
@@ -52,7 +62,7 @@ adc file gpio http i2c mqtt net node ow rtctime si7021 sntp tmr uart wifi
|
||||
|
||||
### Distribution des rôles de NodeMCU
|
||||
|
||||
Comme on peut avoir plusieurs points de mesures à différents endroit dans le local, il n'y a qu'une Seulement fichier de *secrets*. C'est dans ce fichier de *secrets* qu'il y a l'information de l'adresse IP de la base de donnée InfluxDB et c'est l'id des NodeMCU qui sont enregistrés dans la DB InfluxDB !<br>
|
||||
Comme on peut avoir plusieurs points de mesures à différents endroit dans le local, il n'y a qu'un seul fichier de *secrets*. C'est dans ce fichier de *secrets* qu'il y a l'information de l'adresse IP de la base de donnée InfluxDB et c'est l'id des NodeMCU qui sont enregistrés dans la DB InfluxDB !<br>
|
||||
|
||||
```
|
||||
secrets_projet.lua
|
||||
@@ -121,7 +131,7 @@ Seulement la corrélation entre les trois température
|
||||
https://thingspeak.com/apps/plugins/300559
|
||||
|
||||
|
||||
zf191201.2315
|
||||
zf191216.2134
|
||||
|
||||
|
||||
pense bête:
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
print("\n a.lua zf191216.1206 \n")
|
||||
|
||||
t2 = 1234
|
||||
|
||||
id = 0
|
||||
sda = 5
|
||||
scl = 6
|
||||
addr = 0x40
|
||||
|
||||
r = ""
|
||||
HUMIDITY = 0xE5
|
||||
TEMPERATURE = 0xE3
|
||||
|
||||
|
||||
function readHumi()
|
||||
i2c.start(id)
|
||||
i2c.address(id, addr, i2c.TRANSMITTER)
|
||||
i2c.write(id, HUMIDITY)
|
||||
i2c.stop(id)
|
||||
|
||||
i2c.start(id)
|
||||
i2c.address(id, addr, i2c.RECEIVER)
|
||||
tmr.delay(20000)
|
||||
|
||||
r = i2c.read(id,3)
|
||||
i2c.stop(id)
|
||||
|
||||
print(r)
|
||||
return (bit.band((bit.lshift(string.byte(r,1),8)+string.byte(r,2)),0xfffc)*12500)/65536-600
|
||||
end
|
||||
|
||||
|
||||
function getHumidity()
|
||||
return tonumber(string.format("%.1f", tostring(readHumi()/100)))
|
||||
end
|
||||
|
||||
i2c.setup(id, sda, scl, i2c.SLOW)
|
||||
|
||||
t2 = getHumidity()
|
||||
print("Humidity: "..t2.." %")
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
-- http://www.esp8266.com/viewtopic.php?f=19&t=771
|
||||
-- Scan for I2C devices
|
||||
|
||||
print("\n b.lua zf191216.1158 \n")
|
||||
|
||||
id=0
|
||||
sda=5
|
||||
scl=6
|
||||
|
||||
-- initialize i2c, set pin1 as sda, set pin0 as scl
|
||||
|
||||
print("start...")
|
||||
i2c.setup(id,sda,scl,i2c.SLOW)
|
||||
|
||||
for i=0,127 do
|
||||
i2c.start(id)
|
||||
resCode = i2c.address(id, i, i2c.TRANSMITTER)
|
||||
i2c.stop(id)
|
||||
if resCode == true then print("We have a device on address 0x" .. string.format("%02x", i) .. " (" .. i ..")") end
|
||||
end
|
||||
print("stop...")
|
||||
17
Mesures/humidity/bolo/goodies/i2c_scanner.lua
Normal file
17
Mesures/humidity/bolo/goodies/i2c_scanner.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
-- Scanner for I2C devices
|
||||
-- http://www.esp8266.com/viewtopic.php?f=19&t=771
|
||||
|
||||
print("\n i2c_scanner.lua zf191216.2117 \n")
|
||||
|
||||
id=0 sda=5 scl=6
|
||||
|
||||
print("start...")
|
||||
i2c.setup(id,sda,scl,i2c.SLOW)
|
||||
|
||||
for i=0,127 do
|
||||
i2c.start(id)
|
||||
resCode = i2c.address(id, i, i2c.TRANSMITTER)
|
||||
i2c.stop(id)
|
||||
if resCode == true then print("We have a device on address 0x" .. string.format("%02x", i) .. " (" .. i ..")") end
|
||||
end
|
||||
print("stop...")
|
||||
Reference in New Issue
Block a user