![]() |
VOOZH | about |
dotnet add package nanoFramework.Iot.Device.Ds18b20 --version 1.0.903
NuGet\Install-Package nanoFramework.Iot.Device.Ds18b20 -Version 1.0.903
<PackageReference Include="nanoFramework.Iot.Device.Ds18b20" Version="1.0.903" />
<PackageVersion Include="nanoFramework.Iot.Device.Ds18b20" Version="1.0.903" />Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.Ds18b20" />Project file
paket add nanoFramework.Iot.Device.Ds18b20 --version 1.0.903
#r "nuget: nanoFramework.Iot.Device.Ds18b20, 1.0.903"
#:package nanoFramework.Iot.Device.Ds18b20@1.0.903
#addin nuget:?package=nanoFramework.Iot.Device.Ds18b20&version=1.0.903Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.Ds18b20&version=1.0.903Install as a Cake Tool
The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points.
Product datasheet can be found here
Important: make sure you've connected data pin of sensor to two pins on the board!
Important: make sure you properly setup the Rx/Tx pins especially for ESP32 before creating the OneWireHost, make sure you install the nanoFramework.Hardware.ESP32 nuget:
Configuration.SetPinFunction(16, DeviceFunction.COM3_RX);
Configuration.SetPinFunction(17, DeviceFunction.COM3_TX);
private static void ReadingFromOneSensor()
{
OneWireHost oneWire = new OneWireHost();
Ds18b20 ds18b20 = new Ds18b20(oneWire, null, false, TemperatureResolution.VeryHigh);
ds18b20.IsAlarmSearchCommandEnabled = false;
if (ds18b20.Initialize())
{
Console.WriteLine($"Is sensor parasite powered?:{ds18b20.IsParasitePowered}");
string devAddrStr = "";
foreach (var addrByte in ds18b20.Address)
{
devAddrStr += addrByte.ToString("X2");
}
Console.WriteLine($"Sensor address:{devAddrStr}");
while (true)
{
if (!ds18b20.TryReadTemperature(out var currentTemperature))
{
Console.WriteLine("Can't read!");
}
else
{
Console.WriteLine($"Temperature: {currentTemperature.DegreesCelsius.ToString("F")}\u00B0C");
}
Thread.Sleep(5000);
}
}
oneWire.Dispose();
}
private static void NotificationWhenValueHasChanged()
{
OneWireHost oneWire = new OneWireHost();
Ds18b20 ds18b20 = new Ds18b20(oneWire, null, false, TemperatureResolution.VeryHigh);
if (ds18b20.Initialize())
{
ds18b20.SensorValueChanged += (currentTemperature) =>
{
Console.WriteLine($"Temperature: {currentTemperature.DegreesCelsius.ToString("F")}\u00B0C");
};
ds18b20.BeginTrackChanges(TimeSpan.FromMilliseconds(2000));
// do whatever you want or sleep
Thread.Sleep(60000);
ds18b20.EndTrackChanges();
}
oneWire.Dispose();
}
private static void UsingAlarms()
{
using OneWireHost oneWire = new OneWireHost();
Ds18b20 ds18b20 = new Ds18b20(oneWire, null, false, TemperatureResolution.VeryHigh);
if (ds18b20.Initialize())
{
for (int i = 0; i < ds18b20.AddressNet.Length; i++)
{
string devAddrStr = "";
ds18b20.Address = ds18b20.AddressNet[i];
foreach (var addrByte in ds18b20.AddressNet[i])
{
devAddrStr += addrByte.ToString("X2");
}
Console.WriteLine("18b20-" + i.ToString("X2") + " " + devAddrStr);
ds18b20.ConfigurationRead(false);
Console.WriteLine("Alarm set-points before changes:");
Console.WriteLine("Hi alarm = " + ds18b20.TemperatureHighAlarm.DegreesCelsius + " C");
Console.WriteLine("Lo alarm = " + ds18b20.TemperatureLowAlarm.DegreesCelsius + " C");
SetAlarmSetting();
}
alarmSearch();
}
else
{
Console.WriteLine("No devices found.");
}
oneWire.Dispose();
void alarmSearch()
{
int loopRead = 1000;
ds18b20.IsAlarmSearchCommandEnabled = true;
while (loopRead > 0)
{
Console.WriteLine("LoopRead " + loopRead);
if (ds18b20.SearchForAlarmCondition())
{
for (int index = 0; index < ds18b20.AddressNet.Length; index++)
{
ds18b20.Address = ds18b20.AddressNet[index];
if (ds18b20.TryReadTemperature(out var currentTemperature))
{
break;
}
string devAddrStr = "";
foreach (var addrByte in ds18b20.AddressNet[index]) devAddrStr += addrByte.ToString("X2");
Console.WriteLine("DS18B20[" + devAddrStr + "] Sensor reading in One-Shot-mode; T = " + currentTemperature.DegreesCelsius.ToString("f2") + " C");
ds18b20.ConfigurationRead(false);
Console.WriteLine("Alarm set-points:");
Console.WriteLine("Hi alarm = " + ds18b20.TemperatureHighAlarm.DegreesCelsius + " C");
Console.WriteLine("Lo alarm = " + ds18b20.TemperatureLowAlarm.DegreesCelsius + " C");
}
}
else
{
Console.WriteLine("***** No devices in alarm ****");
}
loopRead--;
}
Console.WriteLine("");
}
void SetAlarmSetting()
{
ds18b20.TemperatureHighAlarm = Temperature.FromDegreesCelsius(30);
ds18b20.TemperatureLowAlarm = Temperature.FromDegreesCelsius(25);
// Write configuration on ScratchPad.
ds18b20.ConfigurationWrite(false);
// Write configuration on EEPROM too.
ds18b20.ConfigurationWrite(true);
// Read configuration to check if changes were applied
ds18b20.ConfigurationRead(true);
Console.WriteLine("Alarm set-points after changes:");
Console.WriteLine("Hi alarm = " + ds18b20.TemperatureHighAlarm.DegreesCelsius.ToString("F") + " C");
Console.WriteLine("Lo alarm = " + ds18b20.TemperatureLowAlarm.DegreesCelsius.ToString("F") + " C");
}
}
Check samples project for more usage examples.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net net is compatible. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0-preview.85 | 49 | 6/1/2026 |
| 2.0.0-preview.80 | 62 | 5/27/2026 |
| 2.0.0-preview.73 | 55 | 5/20/2026 |
| 2.0.0-preview.62 | 58 | 5/13/2026 |
| 2.0.0-preview.49 | 55 | 5/4/2026 |
| 2.0.0-preview.45 | 68 | 4/29/2026 |
| 2.0.0-preview.32 | 60 | 4/20/2026 |
| 2.0.0-preview.16 | 61 | 3/10/2026 |
| 1.0.903 | 176 | 3/4/2026 |
| 1.0.840 | 334 | 7/28/2025 |
| 1.0.820 | 366 | 4/2/2025 |
| 1.0.815 | 314 | 4/2/2025 |
| 1.0.803 | 324 | 3/11/2025 |
| 1.0.797 | 303 | 3/10/2025 |
| 1.0.773 | 261 | 2/26/2025 |
| 1.0.726 | 281 | 2/4/2025 |
| 1.0.723 | 262 | 2/4/2025 |
| 1.0.706 | 260 | 1/31/2025 |
| 1.0.694 | 259 | 1/20/2025 |
| 1.0.669 | 275 | 12/30/2024 |