print(string.format("Sensor %s: %s 'C",encoder.toBase64(addr),temp))-- readable address with base64 encoding is preferred when encoder module is available
end
t.setup(gpio0)
-- Module can be released when it is no longer needed
-- Get temperature of first detected sensor in Fahrenheit
print("Total number of DS18B20 sensors: "..table.getn(t.sens))
print("Temperature: "..t.read(nil,t.F).."'F")
fori,sinipairs(t.sens)do
-- print(string.format(" sensor #%d address: %s%s", i, s.addr, s.parasite == 1 and " (parasite)" or ""))
-- Query the second detected sensor, get temperature in Kelvin
print(string.format(" sensor #%d address: %s%s",i,encoder.toBase64(s.addr),s.parasite==1and" (parasite)"or""))-- readable address with base64 encoding is preferred when encoder module is available
resp=resp..string.format("Sensor %s: %s ℃</br>",encoder.toBase64(addr),temp)-- readable address with base64 encoding is preferred when encoder module is available
pin: 1~10, IO index. If parameter is nil, it will use pin 9(GPIO2) automatically.<br/>
####Returns
nil
####Example
```lua
ds18b20=require("ds18b20")
ds18b20.setup(9)
-- Don't forget to release it after use
ds18b20=nil
package.loaded["ds18b20"]=nil
```
####See also
**-**[]()
<aid="ds18b20_addrs"></a>
## addrs()
####Description
Return a table contain all of the addresses of DS18B20 on one-wire. If the setup(pin) function not executed, the pin 9(GPIO2) will be initialized as one-wire mode automatically. <br/>
####Syntax
addrs()
####Parameters
nil
####Returns
addrs: A table contain all of the addresses of DS18B20 on one-wire. Every address is a string. If failed, it will be nil. <br/>
####Example
##readTemp()
```lua
Scans the bus for DS18B20 sensors, starts a readout (conversion) for all sensors and calls a callback function when all temperatures are available. Powered sensors are read at once first. Parasit-powered sensors are read one by one. The first parasit-powered sensor is read together with all powered sensors.
The also module uses `encoder` module for printing debug information with more readable representation of sensor address (`encoder.toBase64()`).
## readNumber()
####Description
Read the value of temperature. If the setup(pin) function not executed, the pin 9(GPIO2) will be initialized as one-wire mode automatically. <br/>
####Syntax
####Syntax
readNumber(addr, unit)
`readTemp(callback, pin)`
####Parameters
####Parameters
addr: string, the address of DS18B20. It will select the first address which be found when this parameter is nil.<br/>
-`callback` function that receives all results when all conversions finish. The callback funciton has one parameter - an array addressed by sensor addresses and a value of the temperature (string for integer version).
unit: integer, unit conversion. Only Constant is acceptable, such as C(Celsius),F(Fahrenheit) and K(Kelvin). If this parameter is nil, the constant C(Celsius) will be selected automatically. <br/>
-`pin` pin of the one-wire bus. If nil, GPIO0 (3) is used.
####Returns
####Returns
t1: integer. The integer part of the temperature. If it read fails, return nil. <br/>
nil
t2: integer. The fractional part of the temperature. If it read fails, return nil. <br/>
Read the string of temperature. If the setup(pin) function not executed, the pin 9(GPIO2) will be initialized as one-wire mode automatically. <br/>
end
####Syntax
-- Module can be released when it is no longer needed
read(addr, unit)
t=nil
package.loaded["ds18b20"]=nil
####Parameters
end
addr: string, the address of DS18B20. It will select the first address which be found when this parameter is nil.<br/>
unit: integer, unit conversion. Only Constant is acceptable, such as C(Celsius),F(Fahrenheit) and K(Kelvin). If this parameter is nil, the constant C(Celsius) will be selected automatically. <br/>
####Returns
t: string. The string of the temperature. If it read fails, return nil.<br/>
####Example
-- t:readTemp(readout) -- default pin value is 3
```lua
t:readTemp(readout,pin)
t=require("ds18b20")
ift.sensthen
t.setup(9)
print("Total number of DS18B20 sensors: "..table.getn(t.sens))
addrs=t.addrs()
fori,sinipairs(t.sens)do
-- Total DS18B20 numbers, assume it is 2
-- print(string.format(" sensor #%d address: %s%s", i, s.addr, s.parasite == 1 and " (parasite)" or ""))
print(table.getn(addrs))
print(string.format(" sensor #%d address: %s%s",i,encoder.toBase64(s.addr),s.parasite==1and" (parasite)"or""))-- readable address with base64 encoding is preferred when encoder module is available