Current Lua downloadable firmware will be posted here

User avatar
By gerardwr
#4177
sancho wrote:Just yesterday I started to work on 1-wire bit-banging! Thanks, will test it today.


I am really curious what kind of pulse accuracy you can achieve in NodeMcu.

On Arduino I use flipping of output pins with securely timed pulses between 1000-5000 microseconds to drive a 433Mhz RF transmitter.

Read in a topic on this board that the tmr.delay was not very precise for short delays. Would like to know what your experience is.

Have fun!
Last edited by gerardwr on Sun Dec 07, 2014 6:11 am, edited 1 time in total.
User avatar
By sancho
#4178 The 1wire works with DS1S20 nd DS18B20.
But I have some trouble with originalDS1820 due to parasitic power only. I had to change the example code - it does not work for more sensors. I'll post it in the evening.
User avatar
By gerardwr
#4179
zeroday wrote: log:
2014-12-07
    3, change net.socket.send() payload max len from 256 to 1460.


Thanks for fixing that, this allows me to display more files in webpages provided by the elua lhttpd webserver.
User avatar
By sancho
#4198 Small update of the script for 1-wire communication - the original version finds the first chip available on the bus and repeats its temperature forewer.
My version finds first address, reads temperature, finds next address, reads temperature and does it for all addresses on the bus and than exists.
Enjoy.
Code: Select allpin = 9
ow.setup(pin)
count = 0

addr = ow.reset_search(pin)
repeat
  count = count + 1
  tmr.wdclr()

if (addr == nil) then
  print("No more addresses.")
else
  print("Address: ")
  print(addr:byte(1,8))
  crc = ow.crc8(string.sub(addr,1,7))
  if (crc == addr:byte(8)) then
    if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then
      print("Device is a DS18S20 family device.")
          ow.reset(pin)
          ow.select(pin, addr)
          ow.write(pin, 0x44, 1)
          tmr.delay(1000000)
          present = ow.reset(pin)
          ow.select(pin, addr)
          ow.write(pin,0xBE, 1)
          print("Present = "..present) 
          data = nil
          data = string.char(ow.read(pin))
          for i = 1, 8 do
            data = data .. string.char(ow.read(pin))
          end
          print(data:byte(1,9))
          crc = ow.crc8(string.sub(data,1,8))
          print("CRC="..crc)
          if (crc == data:byte(9)) then
             t = (data:byte(1) + data:byte(2) * 256) * 625
             t1 = t / 10000
             t2 = t % 10000
             print("Temperature= "..t1.."."..t2.." Centigrade")
          else
             print("Wrong CRC!!!")
          end                   
          tmr.wdclr()
    else
      print("Device family is not recognized.")
    end
  else
    print("CRC is not valid!")
  end
end
addr = ow.search(pin)
until(addr == nil)