Skip to content

Commit e9cf741

Browse files
committed
Added DS18B20 sample
1 parent 3e0739d commit e9cf741

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

dotnet-iot-ds18b20/Program.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Linq;
3+
using Iot.Device.OneWire;
4+
5+
namespace dotnet_iot_ds18b20
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
Console.WriteLine("DS18B20!");
12+
try
13+
{
14+
var devOneWire = OneWireThermometerDevice.EnumerateDevices().FirstOrDefault();
15+
double temp=devOneWire.ReadTemperatureAsync().Result.DegreesCelsius;
16+
Console.WriteLine($"Temperature = {Math.Round(temp, 2, MidpointRounding.AwayFromZero)}");
17+
}
18+
catch (Exception ex)
19+
{
20+
Console.WriteLine($"No 1-Wire sensors found. Exception: {ex.Message}");
21+
}
22+
}
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
<RootNamespace>dotnet_iot_ds18b20</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Iot.Device.Bindings" Version="1.5.0" />
11+
<PackageReference Include="System.Device.Gpio" Version="1.5.0" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31702.278
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-iot-ds18b20", "dotnet-iot-ds18b20.csproj", "{E1F261D1-67DB-4D67-9DC9-4EA8F3C1C7AE}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E1F261D1-67DB-4D67-9DC9-4EA8F3C1C7AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E1F261D1-67DB-4D67-9DC9-4EA8F3C1C7AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E1F261D1-67DB-4D67-9DC9-4EA8F3C1C7AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E1F261D1-67DB-4D67-9DC9-4EA8F3C1C7AE}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {59E05D99-1523-4246-8D44-0A554CA08EEA}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)