Chat freely about anything...

User avatar
By Broncus
#62850 Greetings,

Played around more and not having any success with the ds18b20 module or the example. I was able to move function 'addrs()' from 'ds18b20.lua' into my own test code and I could get the address of the 3 sensors I have connected. So I am definitely missing something in identifying and/or using the module.

At the top of my test code I have this:
Code: Select allt = require("ds18b20")

It is the same as in the example.

Within the ds18b20.lua code, I see this:

Code: Select all--------------------------------------------------------------------------------
-- Set module name as parameter of require
local modname = ...
local M = {}
_G[modname] = M
--------------------------------------------------------------------------------

It is a bit mysterious.
Does it mean I should change the "..." to C, F, or K? or something else?
Or is it just a comment telling the user what is happening?

I see in the example that C, F and K are part of the request for temperature. So the "..." isn't supposed to be any of these.
Code: Select all-- Get temperature of first detected sensor in Fahrenheit
print("Temperature: "..t.read(nil,t.F).."'F")


I am very new at Lua and haven't done much in any other language for about 20 years. I have purchased the '5.1 Reference Manual' and 'Programming in Lua'. They were just delivered yesterday.

Thank you!

Best regards,
Fred

Link: https://github.com/nodemcu/nodemcu-firmware/tree/master/lua_modules/ds18b20
User avatar
By Broncus
#62853 Greetings!

I have success!

First off I am using the code found here:
Code: Select allhttps://github.com/nodemcu/nodemcu-firmware/tree/master/lua_modules/ds18b20

In 'ds18b20-example.lua' I changed line 2 to:
Code: Select allrequire("ds18b20")

Rather than
Code: Select allt = require("ds18b20")

I can't explain the why. I just noticed in the web example 'ds18b20-web.lua' that is how it was used there and tried it.
I also changed every instance of 't.function' to 'ds18b20.function'. Again the 'web' example was the reasoning. So here is my example:
Code: Select allds18b20.setup(pin)
addrs = ds18b20.addrs()

In 'ds18b20.lua' I commented out line 144 since I am using 'integer' rather than 'float'. I believe that is why I was getting this error.
> PANIC: unprotected error in call to Lua API (error loading module 'ds18b20' from file 'ds18b20.lua':
ds18b20.lua:114: malformed number near '1.8')

Best regards,
Fred