This commit is contained in:
Laurent Ellerbach 2021-05-24 13:26:47 +02:00 коммит произвёл GitHub
Родитель 9a59e7fd5d
Коммит 4e1a63df45
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
19 изменённых файлов: 434 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,77 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Buffers.Binary;
using System.Device.I2c;
using System.Device.Model;
using UnitsNet;
namespace Iot.Device.Mlx90614
{
/// <summary>
/// Infra Red Thermometer MLX90614
/// </summary>
[Interface("Infra Red Thermometer MLX90614")]
public sealed class Mlx90614 : IDisposable
{
private I2cDevice _i2cDevice;
/// <summary>
/// MLX90614 Default I2C Address
/// </summary>
public const byte DefaultI2cAddress = 0x5A;
/// <summary>
/// Creates a new instance of the MLX90614
/// </summary>
/// <param name="i2cDevice">The I2C device used for communication.</param>
public Mlx90614(I2cDevice i2cDevice)
{
_i2cDevice = i2cDevice ?? throw new ArgumentNullException(nameof(i2cDevice));
}
/// <summary>
/// Read ambient temperature from MLX90614
/// </summary>
/// <returns>Temperature</returns>
[Telemetry("AmbientTemperature")]
public Temperature ReadAmbientTemperature() => Temperature.FromDegreesCelsius(ReadTemperature((byte)Register.MLX_AMBIENT_TEMP));
/// <summary>
/// Read surface temperature of object from MLX90614
/// </summary>
/// <returns>Temperature</returns>
[Telemetry("ObjectTemperature")]
public Temperature ReadObjectTemperature() => Temperature.FromDegreesCelsius(ReadTemperature((byte)Register.MLX_OBJECT1_TEMP));
/// <summary>
/// Read temperature form specified register
/// </summary>
/// <param name="register">Register</param>
/// <returns>Temperature in celsius</returns>
private double ReadTemperature(byte register)
{
SpanByte writeBuffer = new byte[]
{
register
};
SpanByte readBuffer = new byte[2];
_i2cDevice.WriteRead(writeBuffer, readBuffer);
double temp = BinaryPrimitives.ReadInt16LittleEndian(readBuffer) * 0.02 - 273.15;
return Math.Round(temp * 100) / 100;
}
/// <summary>
/// Cleanup
/// </summary>
public void Dispose()
{
_i2cDevice?.Dispose();
_i2cDevice = null!;
}
}
}

Просмотреть файл

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<NanoFrameworkProjectSystemPath>$(MSBuildToolsPath)..\..\..\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{C466A887-EF03-4789-B3AE-675379836387}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<RootNamespace>Iot.Device.Mlx90614</RootNamespace>
<AssemblyName>Iot.Device.Mlx90614</AssemblyName>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<DocumentationFile>bin\$(Configuration)\Iot.Device.Mlx90614.xml</DocumentationFile>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
<ItemGroup>
<Reference Include="mscorlib">
<HintPath>packages\nanoFramework.CoreLibrary.1.10.4-preview.11\lib\mscorlib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Device.I2c">
<HintPath>packages\nanoFramework.System.Device.I2c.1.0.1-preview.33\lib\System.Device.I2c.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Math">
<HintPath>packages\nanoFramework.System.Math.1.4.0-preview.7\lib\System.Math.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="UnitsNet.Temperature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>packages\UnitsNet.nanoFramework.Temperature.4.92.1\lib\UnitsNet.Temperature.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<Compile Include="Mlx90614.cs" />
<Compile Include="Register.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="*.cs" />
<None Include="*.md" />
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
<Import Project="..\..\src\BinaryPrimitives\BinaryPrimitives.projitems" Label="Shared" />
<Import Project="..\..\src\System.Device.Model\System.Device.Model.projitems" Label="Shared" />
<ProjectExtensions>
<ProjectCapabilities>
<ProjectConfigurationsDeclaredAsItems />
</ProjectCapabilities>
</ProjectExtensions>
<Import Project="packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets" Condition="Exists('packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText> This project references NuGet package(s) that are missing on this computer.Enable NuGet Package Restore to download them.For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets'))" />
</Target>
</Project>

Просмотреть файл

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>nanoFramework.Iot.Device.Mlx90614</id>
<version>$version$</version>
<title>nanoFramework.Iot.Device.Mlx90614</title>
<authors>nanoFramework project contributors</authors>
<owners>nanoFramework project contributors,dotnetfoundation</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="file">LICENSE.md</license>
<releaseNotes>
</releaseNotes>
<developmentDependency>false</developmentDependency>
<projectUrl>https://github.com/nanoframework/nanoFramework.IoT.Device</projectUrl>
<iconUrl>https://secure.gravatar.com/avatar/97d0e092247f0716db6d4b47b7d1d1ad</iconUrl>
<icon>images\nf-logo.png</icon>
<repository type="git" url="https://github.com/nanoframework/nanoFramework.IoT.Device" commit="$commit$" />
<copyright>Copyright (c) .NET Foundation and Contributors</copyright>
<description>This package includes the .NET IoT Core binding Iot.Device.Mlx90614 for .NET nanoFramework C# projects.</description>
<summary>Iot.Device.Mlx90614 assembly for .NET nanoFramework C# projects</summary>
<tags>nanoFramework C# csharp netmf netnf Iot.Device.Mlx90614</tags>
<dependencies>
<dependency id="nanoFramework.CoreLibrary" version="1.10.4-preview.11" />
<dependency id="nanoFramework.System.Device.I2c" version="1.0.1-preview.33" />
<dependency id="nanoFramework.System.Math" version="1.4.0-preview.7" />
<dependency id="UnitsNet.nanoFramework.Temperature" version="4.92.1" />
</dependencies>
</metadata>
<files>
<file src="bin\Release\Iot.Device.Mlx90614.dll" target="lib\Iot.Device.Mlx90614.dll" />
<file src="bin\Release\Iot.Device.Mlx90614.pdb" target="lib\Iot.Device.Mlx90614.pdb" />
<file src="bin\Release\Iot.Device.Mlx90614.pdbx" target="lib\Iot.Device.Mlx90614.pdbx" />
<file src="bin\Release\Iot.Device.Mlx90614.pe" target="lib\Iot.Device.Mlx90614.pe" />
<file src="bin\Release\Iot.Device.Mlx90614.xml" target="lib\Iot.Device.Mlx90614.xml" />
<file src="readme.md" target="" />
<file src="..\..\assets\nf-logo.png" target="images" />
<file src="..\..\LICENSE.md" target="" />
</files>
</package>

Просмотреть файл

@ -0,0 +1,48 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Mlx90614", "Mlx90614.nfproj", "{C466A887-EF03-4789-B3AE-675379836387}"
EndProject
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Mlx90614.Sample", "samples\Mlx90614.Sample.nfproj", "{18C3DEF1-6CB2-4862-BC41-FC68D8A5A8EB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Share Projects", "Share Projects", "{BC503E10-85E9-41C7-8F44-9849D2B38042}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "BinaryPrimitives", "..\..\src\BinaryPrimitives\BinaryPrimitives.shproj", "{3F28B003-6318-4E21-A9B6-6C0DBD0BDBFD}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "System.Device.Model", "..\..\src\System.Device.Model\System.Device.Model.shproj", "{23325B14-3651-4879-9697-9846FF123FEB}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\..\src\System.Device.Model\System.Device.Model.projitems*{23325b14-3651-4879-9697-9846ff123feb}*SharedItemsImports = 13
..\..\src\BinaryPrimitives\BinaryPrimitives.projitems*{3f28b003-6318-4e21-a9b6-6c0dbd0bdbfd}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C466A887-EF03-4789-B3AE-675379836387}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C466A887-EF03-4789-B3AE-675379836387}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C466A887-EF03-4789-B3AE-675379836387}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{C466A887-EF03-4789-B3AE-675379836387}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C466A887-EF03-4789-B3AE-675379836387}.Release|Any CPU.Build.0 = Release|Any CPU
{C466A887-EF03-4789-B3AE-675379836387}.Release|Any CPU.Deploy.0 = Release|Any CPU
{18C3DEF1-6CB2-4862-BC41-FC68D8A5A8EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18C3DEF1-6CB2-4862-BC41-FC68D8A5A8EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18C3DEF1-6CB2-4862-BC41-FC68D8A5A8EB}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{18C3DEF1-6CB2-4862-BC41-FC68D8A5A8EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18C3DEF1-6CB2-4862-BC41-FC68D8A5A8EB}.Release|Any CPU.Build.0 = Release|Any CPU
{18C3DEF1-6CB2-4862-BC41-FC68D8A5A8EB}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3F28B003-6318-4E21-A9B6-6C0DBD0BDBFD} = {BC503E10-85E9-41C7-8F44-9849D2B38042}
{23325B14-3651-4879-9697-9846FF123FEB} = {BC503E10-85E9-41C7-8F44-9849D2B38042}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {79ED299D-8816-4D85-A68A-AD25600C80EB}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,10 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Iot.Device.Mlx90614")]
[assembly: AssemblyCompany("nanoFramework Contributors")]
[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")]
[assembly: ComVisible(false)]

Просмотреть файл

@ -0,0 +1,24 @@
# MLX90614 - Infra Red Thermometer
The MLX90614 is an Infra Red thermometer for noncontact temperature measurements. Both the IR sensitive thermopile detector chip and the signal conditioning ASSP are integrated in the same TO-39 can. Thanks to its low noise amplifier, 17-bit ADC and powerful DSP unit, a high accuracy and resolution of the thermometer is achieved.
## Sensor Image
![](sensor.jpg)
## Usage
```C#
I2cConnectionSettings settings = new I2cConnectionSettings(1, Mlx90614.DefaultI2cAddress);
I2cDevice i2cDevice = I2cDevice.Create(settings);
using (Mlx90614 sensor = new Mlx90614(i2cDevice))
{
// read ambient temperature
double ambient = sensor.ReadAmbientTemperature().Celsius;
// read object temperature
double object = sensor.ReadObjectTemperature().Celsius;
}
```
## References
https://cdn.datasheetspdf.com/pdf-down/M/L/X/MLX90614-Melexis.pdf

Просмотреть файл

@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Iot.Device.Mlx90614
{
internal enum Register
{
MLX_AMBIENT_TEMP = 0x06,
MLX_OBJECT1_TEMP = 0x07
}
}

Просмотреть файл

@ -0,0 +1,2 @@
thermometer
infrared

Просмотреть файл

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nanoFramework.CoreLibrary" version="1.10.4-preview.11" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Device.I2c" version="1.0.1-preview.33" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Math" version="1.4.0-preview.7" targetFramework="netnanoframework10" />
<package id="Nerdbank.GitVersioning" version="3.4.194" developmentDependency="true" targetFramework="netnanoframework10" />
<package id="UnitsNet.nanoFramework.Temperature" version="4.92.1" targetFramework="netnanoframework10" />
</packages>

Двоичные данные
devices/Mlx90614/samples/MLX90614_circuit.fzz Normal file

Двоичный файл не отображается.

Двоичные данные
devices/Mlx90614/samples/MLX90614_circuit_bb.jpg Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 220 KiB

Просмотреть файл

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<NanoFrameworkProjectSystemPath>$(MSBuildToolsPath)..\..\..\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{18C3DEF1-6CB2-4862-BC41-FC68D8A5A8EB}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<RootNamespace>Iot.Device.Mlx90614.Sample</RootNamespace>
<AssemblyName>Iot.Device.Mlx90614.Sample</AssemblyName>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<DocumentationFile>bin\$(Configuration)\Iot.Device.Mlx90614.Sample.xml</DocumentationFile>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
<ItemGroup>
<Reference Include="mscorlib">
<HintPath>..\packages\nanoFramework.CoreLibrary.1.10.4-preview.11\lib\mscorlib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Device.I2c">
<HintPath>..\packages\nanoFramework.System.Device.I2c.1.0.1-preview.33\lib\System.Device.I2c.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="UnitsNet.Temperature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\UnitsNet.nanoFramework.Temperature.4.92.1\lib\UnitsNet.Temperature.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<!-- INSERT FILE REFERENCES HERE -->
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="*.cs" />
<None Include="*.md" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mlx90614.nfproj" />
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
<!-- INSERT IMPORTS HERE -->
<ProjectExtensions>
<ProjectCapabilities>
<ProjectConfigurationsDeclaredAsItems />
</ProjectCapabilities>
</ProjectExtensions>
<!-- INSERT NBGV IMPORT HERE -->
</Project>

Просмотреть файл

@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Device.I2c;
using System.Diagnostics;
using System.Threading;
using Iot.Device.Mlx90614;
I2cConnectionSettings settings = new(1, Mlx90614.DefaultI2cAddress);
using I2cDevice i2cDevice = I2cDevice.Create(settings);
using Mlx90614 sensor = new(i2cDevice);
while (true)
{
Debug.WriteLine($"Ambient: {sensor.ReadAmbientTemperature().DegreesCelsius} ℃");
Debug.WriteLine($"Object: {sensor.ReadObjectTemperature().DegreesCelsius} ℃");
Debug.WriteLine("");
Thread.Sleep(1000);
}

Просмотреть файл

@ -0,0 +1,10 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Iot.Device.Mlx90614.Sample")]
[assembly: AssemblyCompany("nanoFramework Contributors")]
[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")]
[assembly: ComVisible(false)]

Просмотреть файл

@ -0,0 +1,36 @@
# MLX90614 - Samples
## Hardware Required
* MLX90614
* Male/Female Jumper Wires
## Circuit
![](MLX90614_circuit_bb.jpg)
* SCL - SCL (GPIO 3)
* SDA - SDA (GPIO 2)
* VCC - 5V/3V
* GND - GND
**Warning: MLX90614 includes 5V and 3V versions!**
## Code
```C#
I2cConnectionSettings settings = new I2cConnectionSettings(1, Mlx90614.DefaultI2cAddress);
I2cDevice i2cDevice = I2cDevice.Create(settings);
using (Mlx90614 sensor = new Mlx90614(i2cDevice))
{
while (true)
{
Console.WriteLine($"Ambient: {sensor.ReadAmbientTemperature().Celsius} ℃");
Console.WriteLine($"Object: {sensor.ReadObjectTemperature().Celsius} ℃");
Console.WriteLine();
Thread.Sleep(1000);
}
}
```
## Result
![](RunningResult.jpg)

Двоичные данные
devices/Mlx90614/samples/RunningResult.jpg Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 27 KiB

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nanoFramework.CoreLibrary" version="1.10.4-preview.11" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Device.I2c" version="1.0.1-preview.33" targetFramework="netnanoframework10" />
<package id="UnitsNet.nanoFramework.Temperature" version="4.92.1" targetFramework="netnanoframework10" />
</packages>

Двоичные данные
devices/Mlx90614/sensor.jpg Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 74 KiB

Просмотреть файл

@ -0,0 +1,19 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.0",
"assemblyVersion": {
"precision": "minor"
},
"semVer1NumericIdentifierPadding": 3,
"nuGetPackageVersion": {
"semVer": 2.0
},
"publicReleaseRefSpec": [
"^refs/heads/develop$",
"^refs/heads/main$",
"^refs/heads/v\\d+(?:\\.\\d+)?$"
],
"cloudBuild": {
"setAllVariables": true
}
}