-->
Page 6 of 8

Re: Example - measure temperature using 1-wire DS1820

PostPosted: Fri Jan 16, 2015 4:01 pm
by gwizz
Hiya ChrixXenon

The reference to 4 needs to be understood as an internal reference number. They are mapped using the GPIO mapping table here https://github.com/nodemcu/nodemcu-firmware/#gpio-old-table-before-build-20141212.

It means that you should wire the DS18B20 signal wire (often yellow in pre-wired waterproof sensors) to the GPIO2 pin.

I made a little one-liner you can include in your scripts if you like that means you can use the normal GPIO numbers.

Code: Select allgpio= {[0]=3,[2]=4,[4]=2,[5]=1,[12]=6,[13]=7,[14]=5,[15]=8,[16]=0}


After this line you can refer to pins like this:

Code: Select allpin=gpio[2] -- connect the signal wire to pin GPIO2


hth

G

Re: Example - measure temperature using 1-wire DS1820

PostPosted: Sun Jan 18, 2015 7:17 am
by ChrixXenon
Thanks very much for your clarification.

Re: Example - measure temperature using 1-wire DS1820

PostPosted: Fri Feb 20, 2015 8:18 pm
by Jeckert
Here is how I solved the number conversion on the esp8266 with a DS18B20. It works with both positive and negative numbers.
Code: Select allfunction trim(s)
  return (s:gsub("^%s*(.-)%s*$", "%1"))
end
rt1=("0x"..trim(string.format('%02X ', data:byte(2)))..trim(string.format('%02X ', data:byte(1))).."" )
s=""
rt2=rt1
   if (rt1+0) > 2001 then
     s="-"
     rt2=(bit.bxor(rt1, 0xffff)+1)
   end
td=bit.band(rt2,15)
td=(td*.0625)
tn=(bit.rshift(rt2, 4))
print(s..(tn+td))

Re: Example - measure temperature using 1-wire DS1820

PostPosted: Fri Jul 03, 2015 8:56 pm
by OG Style
I'm having trouble with it. I keep getting.
nettemp.pl ds18b20
Temperature: -1.625

I'm using this script.
https://raw.githubusercontent.com/sospr ... s/init.lua

I'm wired up this way.
http://vaasa.hacklab.fi/wordpress/wp-co ... _ds_bb.png

Thanks