DS18B20
Info: Currently unused, soon to be discontinued.
DS18B20 Functions
This category contains functions specific to DS18B20 temperature sensors.
| API Name | Brief Description |
|---|---|
| api.ds18b20GetTemp(pwrpin, datapin, address) | Returns temperature in millidegrees Celsius from DS18B20. |
| api.ds18b20Search(pwrpin, datapin, numdev) | Searches for DS18B20 devices on the 1-Wire bus. |
api.ds18b20GetTemp(pwrpin, datapin, address)
api.ds18b20GetTemp(1, 2)
Returns temperature in millidegrees Celsius (m°C) from DS18B20.
Info: In case of using multiple DS18B20 sensors connected to one data pin, it’s possible to address a specific DS18B20 with its ID.
Warning: Disabled by default, requires firmware and hardware changes.
Arguments
- pwrpin (integer): Power pin number.
- datapin (integer): Data pin number.
Optional
- address (array, optional): Array of numbers used as address (8 bytes). When no array is specified, gets temperature from the first 1-Wire device.
Return
- temperature (integer): Temperature in millidegrees Celsius.
Example
-- Search all devices on the 1-Wire bus
found = api.ds18b20Search(1, 2)
-- `found` contains a table of addresses of found devices or `nil` if no device was found
-- Print count of devices found
if found then
print("Found " .. #found .. " devices")
-- Loop over all addresses
for i = 1, #found, 1 do
temp = api.ds18b20GetTemp(1, 2, found[i])
temp = temp / 1000
print("Teplomer #" .. i .. " " .. temp .. "C")
end
else
print("No devices found!")
end
-- Without addressing (one sensor = one data pin)
res1 = api.ds18b20GetTemp(1, 2) -- get temperature from sensor connected to data pin 2
print("Temperature: " .. tostring(res1) .. " mDeg.C")
api.ds18b20Search(pwrpin, datapin, numdev)
api.ds18b20Search(1, 2)
Searches for DS18B20 devices on the 1-Wire bus.
Arguments
- pwrpin (integer): Power pin number.
- datapin (integer): Data pin number.
Optional
- numdev (integer, optional): Number of found devices to stop the scan after.
Return
- addresses (integer):
nilor array of addresses found on the specified bus.
Example
-- Find addresses of up to 3 sensors
api.ds18b20Search(1, 2, 3)