pin = 4
ow.setup(pin)
count = 0
newaddr = nil
addr = nil
addrs = {}
i = 0
ow.reset_search(pin)
repeat
count = count + 1
newaddr = ow.search(pin)
if (newaddr ~= nil) then
addrs[i]=newaddr
print("i: ",i,"addr: ",newaddr:byte(1,8))
i = i + 1
end
tmr.wdclr()
until((count > 100))
The data is then uploaded to ThinkSpeak every minute. It can be seen here
https://thingspeak.com/channels/79123
I have attached a lua code snippet which is now stable and working well on my setup.
You can modify it to your needs ie 3x sensors and the temperature data will be returned in t1 to t3
Things to note:
Needs the module ds18b20.lua to run. Download from
https://github.com/StormTrooper/ESP8266 ... s18b20.lua
I use gpio0 just change to suit your setup
Works with Integer firmware but needs the one wire module.
Get the custom firmware from nodemcu-build.com and check the box 1-wire
A drawback was that after first power up 85 deg C is returned. To overcome this I added a 750mSec delay (tmr.delay(750000)) in the ds18b20.lua module at line 85.
This slows the reading time for each sensor, but it works.
Hope this helps
-- One Wire DS18B20 function for 6 sensors
-- Jeepers01 February 2016
--
-- call function with getDSdata() as required
-- t1 to t6 sequence is as I had labelled them and not the unique ID sequence
-- Hence the sequence is t1,t5,t6,t2,t3,t4
-- Module ds18b20.lua is required
--
gpio= {[0]=3,[2]=4,[4]=2,[5]=1,[12]=6,[13]=7,[14]=5,[15]=8,[16]=0}
--
function getDSdata()
pin=gpio[0] -- connect the signal wire to pin GPIO0
t=require("ds18b20")
t.setup(pin) -- gpio0
addrs=t.addrs()
node_id = node.chipid()
print("Total Sensors.: "..table.getn(addrs).." ")
print("Sensor Type...: "..node_id.." ")
hex_format="%02X%02X%02X%02X%02X%02X%02X%02X"
sensor_count=table.getn(addrs)
if (sensor_count>0) then
for i=1,sensor_count do
sid=string.format(hex_format,string.byte(addrs[i],1,9))
print("t"..i.." Unique ID : "..sid.." ")
tmr.wdclr()
end
end
t1 = t.read(addrs[1],t.C)
t5 = t.read(addrs[2],t.C)
t6 = t.read(addrs[3],t.C)
t2 = t.read(addrs[4],t.C)
t3 = t.read(addrs[5],t.C)
t4 = t.read(addrs[6],t.C)
print("Temp t1 Lower.: "..t1.." deg C")
print("Temp t2 Upper.: "..t2.." deg C")
print("Temp t3 Middle: "..t3.." deg C")
print("Temp t4 Top...: "..t4.." deg C")
print("Temp t5 Flow..: "..t5.." deg C")
print("Temp t6 Return: "..t6.." deg C")
-- Cleanup
t = nil
ds18b20 = nil
package.loaded["ds18b20"]=nil
end
Sensor count is always 0
Total Sensors.: 0
Sensor Type...: 13579964
0
Temp t1 Top.: 25.25.2500 deg C
Temp t2 Mid.: 25.25.2500 deg C
What i have tried so far where 1 Sensor is working but more are not recognized :
GPIO with buildin Pullup
GPIO configured as OUTPUT
external Pullup
parasite mode for the sensor
external Power
10 different sensors (all are working)
build in a BUS query delay ...
ds18b20.lua from NodeMCU
your mentioned ds18b20.lua from stormtroppers
result is always same sh** ....
So only thing i can emagine is the Firmware. Any other ideas ? Any help would be much appreciated.
best regards
/Lord Richard of Kerry/
--
gpio= {[0]=3,[2]=4,[4]=2,[5]=1,[12]=6,[13]=7,[14]=5,[15]=8,[16]=0}
--
function getDSdata()
pin=gpio[2] -- connect the signal wire to pin 4 /GPIO2
t=require("ds18b20")
t.setup(pin) -- gpio2
addrs=t.addrs()
node_id = node.chipid()
print("Total Sensors.: "..table.getn(addrs).." ")
print("Sensor Type...: "..node_id.." ")
hex_format="%02X%02X%02X%02X%02X%02X%02X%02X"
sensor_count=table.getn(addrs)
if (sensor_count>0) then
for i=1,sensor_count do
sid=string.format(hex_format,string.byte(addrs[i],1,9))
print("t"..i.." Unique ID : "..sid.." ")
tmr.wdclr()
end
end
t1 = t.read(addrs[1],t.C)
t2 = t.read(addrs[2],t.C)
t3 = t.read(addrs[3],t.C)
print("Temp t1 Top.: "..t1.." deg C")
print("Temp t2 Mid.: "..t2.." deg C")
print("Temp t2 Bottom.: "..t2.." deg C")
-- Cleanup
t = nil
ds18b20 = nil
package.loaded["ds18b20"]=nil
end
function addrs()
setup(pin)
tbl = {}
ow.reset_search(pin)
repeat
tmr.delay(750000)
addr = ow.search(pin)
if(addr ~= nil) then
table.insert(tbl, addr)
end
tmr.wdclr()
until (addr == nil)
ow.reset_search(pin)
return tbl
end
UPDATE
Shortly after sending this post i have found a solution ...... Problem is explained in below given thread and sorted by updating to a new firmware https://github.com/nodemcu/nodemcu-firmware/issues/429
Thanks anyway !
if (crc == data:byte(9)) then
t = (data:byte(1) + data:byte(2) * 256)
if (t > 32767) then
t = t - 65535
end
if(unit == nil or unit == C) then
t = t * 625
elseif(unit == F) then
t = t * 1125 + 320000
elseif(unit == K) then
t = t * 625 + 2731500
else