Post your best Lua script examples here

User avatar
By teddyz
#26416 Hello all

I have failed getting DS18B20 example to work.
Code: Select allt = require("ds18b20")

-- ESP-01 GPIO Mapping
gpio0 = 3
gpio2 = 4

t.setup(gpio2)
addrs = t.addrs()
if (addrs ~= nil) then
  print("Total DS18B20 sensors: "..table.getn(addrs))
end

-- Just read temperature
print("Temperature: "..t.read().."'C")

-- Don't forget to release it after use
t = nil
ds18b20 = nil
package.loaded["ds18b20"]=nil


The answer I get is
Code: Select allds18b20.lua:80: attempt to index local 'addr' (a number value)

I wonder if this is because it does not detect my sensors (three with pull-up resistor) or if the library needs to be modified.
Also, what command is used to read fw version from the ESP?

Thanks,
Dick
User avatar
By teddyz
#26816 I didn't know that nodemcu flasher application has an old fw ("NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4") inside. I assumed it downloaded the latest one. After I downloaded the latest float-version of the firmware I got it somewhat working. Still I have trouble finding all my sensors, but that can of course have other explanations. They might not be good at 3.3V or my pull-up resistor might have wrong value.

I did not find any other way of getting fw version than watching the terminal from start.