updated ina219 to work with nano (#192)
* updated ina219 to work with nano * fixed nupsec * updated ina219 to work with nano * fixed nupsec * Fixed nfproj Co-authored-by: José Simões <jose.simoes@eclo.solutions> Co-authored-by: Laurent Ellerbach <laurelle@microsoft.com>
This commit is contained in:
Родитель
6faa8469f2
Коммит
6c6024d4e8
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Collections.Generic;
|
||||
using System.Device;
|
||||
using System.Device.I2c;
|
||||
using System.Device.Model;
|
||||
|
@ -26,20 +25,24 @@ namespace Iot.Device.Adc
|
|||
{
|
||||
// These values are the datasheet defined delays in micro seconds between requesting a Current or Power value from the INA219 and the ADC sampling having completed
|
||||
// along with any conversions.
|
||||
private static readonly Dictionary<Ina219AdcResolutionOrSamples, int> s_readDelays = new()
|
||||
private static int s_readDelays(Ina219AdcResolutionOrSamples adc)
|
||||
{
|
||||
{ Ina219AdcResolutionOrSamples.Adc9Bit, 84 },
|
||||
{ Ina219AdcResolutionOrSamples.Adc10Bit, 148 },
|
||||
{ Ina219AdcResolutionOrSamples.Adc11Bit, 276 },
|
||||
{ Ina219AdcResolutionOrSamples.Adc12Bit, 532 },
|
||||
{ Ina219AdcResolutionOrSamples.Adc2Sample, 1006 },
|
||||
{ Ina219AdcResolutionOrSamples.Adc4Sample, 2130 },
|
||||
{ Ina219AdcResolutionOrSamples.Adc8Sample, 4260 },
|
||||
{ Ina219AdcResolutionOrSamples.Adc16Sample, 8510 },
|
||||
{ Ina219AdcResolutionOrSamples.Adc32Sample, 17020 },
|
||||
{ Ina219AdcResolutionOrSamples.Adc64Sample, 34050 },
|
||||
{ Ina219AdcResolutionOrSamples.Adc128Sample, 68100 }
|
||||
};
|
||||
switch(adc)
|
||||
{
|
||||
case Ina219AdcResolutionOrSamples.Adc9Bit: return 84;
|
||||
case Ina219AdcResolutionOrSamples.Adc10Bit: return 148;
|
||||
case Ina219AdcResolutionOrSamples.Adc11Bit: return 276;
|
||||
case Ina219AdcResolutionOrSamples.Adc12Bit: return 532;
|
||||
case Ina219AdcResolutionOrSamples.Adc2Sample: return 1006;
|
||||
case Ina219AdcResolutionOrSamples.Adc4Sample: return 2130;
|
||||
case Ina219AdcResolutionOrSamples.Adc8Sample: return 4260;
|
||||
case Ina219AdcResolutionOrSamples.Adc16Sample: return 8510;
|
||||
case Ina219AdcResolutionOrSamples.Adc32Sample: return 17020;
|
||||
case Ina219AdcResolutionOrSamples.Adc64Sample: return 34050;
|
||||
case Ina219AdcResolutionOrSamples.Adc128Sample: return 68100;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private I2cDevice _i2cDevice;
|
||||
private bool _disposeI2cDevice = false;
|
||||
|
@ -241,7 +244,7 @@ namespace Iot.Device.Adc
|
|||
/// <returns>The shunt potential difference</returns>
|
||||
// read the shunt voltage. LSB = 10uV then convert to Volts
|
||||
[Telemetry("ShuntVoltage")]
|
||||
public ElectricPotential ReadShuntVoltage() => ElectricPotential.FromVolts(ReadRegister(Ina219Register.ShuntVoltage, s_readDelays[(Ina219AdcResolutionOrSamples)_shuntAdcResSamp]) * 10.0 / 1000000.0);
|
||||
public ElectricPotential ReadShuntVoltage() => ElectricPotential.FromVolts(ReadRegister(Ina219Register.ShuntVoltage, s_readDelays(_shuntAdcResSamp)) * 10.0 / 1000000.0);
|
||||
|
||||
/// <summary>
|
||||
/// Read the measured Bus voltage.
|
||||
|
@ -249,7 +252,7 @@ namespace Iot.Device.Adc
|
|||
/// <returns>The Bus potential (voltage)</returns>
|
||||
// read the bus voltage. LSB = 4mV then convert to Volts
|
||||
[Telemetry("BusVoltage")]
|
||||
public ElectricPotential ReadBusVoltage() => ElectricPotential.FromVolts(((short)ReadRegister(Ina219Register.BusVoltage, s_readDelays[_busAdcResSamp]) >> 3) * 4 / 1000.0);
|
||||
public ElectricPotential ReadBusVoltage() => ElectricPotential.FromVolts(((short)ReadRegister(Ina219Register.BusVoltage, s_readDelays(_busAdcResSamp)) >> 3) * 4 / 1000.0);
|
||||
|
||||
/// <summary>
|
||||
/// Read the calculated current through the INA219.
|
||||
|
@ -267,7 +270,7 @@ namespace Iot.Device.Adc
|
|||
// whenever needed.
|
||||
SetCalibration(_calibrationValue, _currentLsb);
|
||||
|
||||
return ElectricCurrent.FromAmperes(ReadRegister(Ina219Register.Current, s_readDelays[(Ina219AdcResolutionOrSamples)_shuntAdcResSamp]) * _currentLsb);
|
||||
return ElectricCurrent.FromAmperes(ReadRegister(Ina219Register.Current, s_readDelays(_shuntAdcResSamp)) * _currentLsb);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -286,7 +289,7 @@ namespace Iot.Device.Adc
|
|||
// whenever needed.
|
||||
SetCalibration(_calibrationValue, _currentLsb);
|
||||
|
||||
return Power.FromWatts(ReadRegister(Ina219Register.Power, s_readDelays[(Ina219AdcResolutionOrSamples)_shuntAdcResSamp]) * _currentLsb * 20);
|
||||
return Power.FromWatts(ReadRegister(Ina219Register.Power, s_readDelays(_shuntAdcResSamp)) * _currentLsb * 20);
|
||||
}
|
||||
|
||||
/// <summary>
|
Двоичный файл не отображается.
|
@ -18,50 +18,82 @@
|
|||
<DocumentationFile>bin\$(Configuration)\Iot.Device.Ina219.xml</DocumentationFile>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>..\key.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<DelaySign>false</DelaySign>
|
||||
</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>
|
||||
<Reference Include="mscorlib, Version=1.10.5.4, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>packages\nanoFramework.CoreLibrary.1.10.5\lib\mscorlib.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.I2c">
|
||||
<HintPath>packages\nanoFramework.System.Device.I2c.1.0.1-preview.33\lib\System.Device.I2c.dll</HintPath>
|
||||
<HintPath>packages\nanoFramework.System.Device.I2c.1.0.1\lib\System.Device.I2c.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.Model">
|
||||
<HintPath>packages\nanoFramework.System.Device.Model.1.0.176\lib\System.Device.Model.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Buffers.Binary.BinaryPrimitives">
|
||||
<HintPath>packages\nanoFramework.System.Buffers.Binary.BinaryPrimitives.1.0.160\lib\System.Buffers.Binary.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnitsNet.RelativeHumidity">
|
||||
<HintPath>packages\UnitsNet.nanoFramework.RelativeHumidity.4.92.0\lib\UnitsNet.RelativeHumidity.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnitsNet.Temperature">
|
||||
<HintPath>packages\UnitsNet.nanoFramework.Temperature.4.92.0\lib\UnitsNet.Temperature.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>
|
||||
</Reference>
|
||||
<Reference Include="UnitsNet.ElectricPotential">
|
||||
<HintPath>packages\UnitsNet.nanoFramework.ElectricPotential.4.92.0\lib\UnitsNet.ElectricPotential.dll</HintPath>
|
||||
<HintPath>packages\UnitsNet.nanoFramework.ElectricPotential.4.102.0\lib\UnitsNet.ElectricPotential.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnitsNet.ElectricCurrent">
|
||||
<HintPath>packages\UnitsNet.nanoFramework.ElectricCurrent.4.92.0\lib\UnitsNet.ElectricCurrent.dll</HintPath>
|
||||
<HintPath>packages\UnitsNet.nanoFramework.ElectricCurrent.4.102.0\lib\UnitsNet.ElectricCurrent.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnitsNet.Power">
|
||||
<HintPath>packages\UnitsNet.nanoFramework.Power.4.102.0\lib\UnitsNet.Power.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Diagnostics.Stopwatch, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>packages\nanoFramework.System.Diagnostics.Stopwatch.1.0.160\lib\System.Diagnostics.Stopwatch.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<Compile Include="*.cs" />
|
||||
<Compile Include="..\Common\System\Device\DelayHelper.cs" Link="DelayHelper.cs" />
|
||||
<None Include="README.md" />
|
||||
</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" />
|
||||
<Import Project="..\..\src\System.Runtime.CompilerService\System.Runtime.CompilerService.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">
|
||||
<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'))" />
|
||||
<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>
|
||||
</Project>
|
|
@ -5,14 +5,14 @@
|
|||
<version>$version$</version>
|
||||
<title>nanoFramework.Iot.Device.Ina219</title>
|
||||
<authors>nanoFramework project contributors</authors>
|
||||
<owners>nanoFramework,dotnetfoundation</owners>
|
||||
<owners>nanoFramework project contributors,dotnetfoundation</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<license type="file">LICENSE.md</license>
|
||||
<releaseNotes>
|
||||
</releaseNotes>
|
||||
<readme>docs\README.md</readme>
|
||||
<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>
|
||||
|
@ -20,7 +20,14 @@
|
|||
<summary>Iot.Device.Ina219 assembly for .NET nanoFramework C# projects</summary>
|
||||
<tags>nanoFramework C# csharp netmf netnf Iot.Device.Ina219</tags>
|
||||
<dependencies>
|
||||
<dependency id="nanoFramework.CoreLibrary" version="1.10.4-preview.11" />
|
||||
<dependency id="nanoFramework.CoreLibrary" version="1.10.5" />
|
||||
<dependency id="nanoFramework.System.Device.I2c" version="1.0.1" />
|
||||
<dependency id="nanoFramework.System.Buffers.Binary.BinaryPrimitives" version="1.0.160" />
|
||||
<dependency id="nanoFramework.System.Device.Model" version="1.0.176" />
|
||||
<dependency id="UnitsNet.nanoFramework.ElectricPotential" version="4.102.0" />
|
||||
<dependency id="UnitsNet.nanoFramework.ElectricCurrent" version="4.102.0" />
|
||||
<dependency id="UnitsNet.nanoFramework.Power" version="4.102.0" />
|
||||
<dependency id="nanoFramework.System.Diagnostics.Stopwatch" version="1.0.160" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
|
@ -29,9 +36,8 @@
|
|||
<file src="bin\Release\Iot.Device.Ina219.pdbx" target="lib\Iot.Device.Ina219.pdbx" />
|
||||
<file src="bin\Release\Iot.Device.Ina219.pe" target="lib\Iot.Device.Ina219.pe" />
|
||||
<file src="bin\Release\Iot.Device.Ina219.xml" target="lib\Iot.Device.Ina219.xml" />
|
||||
|
||||
<file src="README.md" target="docs\" />
|
||||
<file src="..\assets\nf-logo.png" target="images" />
|
||||
<file src="..\LICENSE.md" target="" />
|
||||
<file src="readme.md" target="" />
|
||||
<file src="..\..\assets\nf-logo.png" target="images" />
|
||||
<file src="..\..\LICENSE.md" target="" />
|
||||
</files>
|
||||
</package>
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 158 KiB |
|
@ -0,0 +1,55 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31613.86
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{0D478BAB-AFEA-4AF1-866C-E3AC32E11C5A}"
|
||||
EndProject
|
||||
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Ina219.Samples", "samples\Ina219.Samples.nfproj", "{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}"
|
||||
EndProject
|
||||
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Ina219", "Ina219.nfproj", "{B6CCC350-F739-17FD-CD00-45080F7DC9DB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Release|x64.Build.0 = Release|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456}.Release|x86.Build.0 = Release|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Release|x64.Build.0 = Release|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{B6CCC350-F739-17FD-CD00-45080F7DC9DB}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{A9A1A6D6-C30A-7911-C4E4-63AE0A28F456} = {0D478BAB-AFEA-4AF1-866C-E3AC32E11C5A}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {380E67F7-D17E-418A-9E95-C97B1FB2219C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -15,14 +15,19 @@ This binding is intended to support both the A and B grades of the INA219. The g
|
|||
|
||||
* [INA219 Datasheet](http://www.ti.com/lit/ds/symlink/ina219.pdf)
|
||||
|
||||
## Board
|
||||
|
||||
![image](./Ina219.png)
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```csharp
|
||||
const byte Adafruit_Ina219_I2cAddress = 0x40;
|
||||
const byte Adafruit_Ina219_I2cBus = 0x1;
|
||||
const byte Ina219_I2cAddress = 0x40;
|
||||
const byte Ina219_I2cBus = 0x1;
|
||||
|
||||
// create an INA219 device on I2C bus 1 addressing channel 64
|
||||
using (Ina219 device = new Ina219(new I2cConnectionSettings(Adafruit_Ina219_I2cBus, Adafruit_Ina219_I2cAddress)))
|
||||
using (Ina219 device = new Ina219(new I2cConnectionSettings(Ina219_I2cBus, Ina219_I2cAddress)))
|
||||
{
|
||||
// reset the device
|
||||
device.Reset();
|
||||
|
@ -43,7 +48,7 @@ using (Ina219 device = new Ina219(new I2cConnectionSettings(Adafruit_Ina219_I2cB
|
|||
|
||||
### Notes
|
||||
|
||||
This sample uses an Adafruit INA219 breakout board and monitors a LED wired into the 3.3 volts supply with a 150 ohm current limiting resistor. It prints the bus voltage, shunt voltage, current and power every second.
|
||||
This sample uses an INA219 breakout board and monitors a LED wired into the 3.3 volts supply with a 150 ohm current limiting resistor. It prints the bus voltage, shunt voltage, current and power every second.
|
||||
|
||||
The configuration and calibration is determinined as follows.
|
||||
|
||||
|
@ -53,5 +58,3 @@ at 5mV. Given this we can use a shunt voltage range of +/- 40mV
|
|||
* The maximum possible current would then be 40mV / 0.1 = 400mA
|
||||
* With a 400mA maximum current and a range of the ADC of 15bits then the LSB of the current would be 400mA/32767 = 12.2207 microamps. We will chose 12.2uA as a round number.
|
||||
* From the [INA219 Datasheet](http://www.ti.com/lit/ds/symlink/ina219.pdf) the calibration register should be set at 0.04096/(currentLSB * shunt resistance) = 33574 = 0x8326
|
||||
|
||||
![circuit](Ina219.Sample_bb.png)
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="nanoFramework.CoreLibrary" version="1.10.5" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.I2c" version="1.0.1" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Buffers.Binary.BinaryPrimitives" version="1.0.160" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.Model" version="1.0.176" targetFramework="netnanoframework10" />
|
||||
<package id="UnitsNet.nanoFramework.ElectricPotential" version="4.102.0" targetFramework="netnanoframework10" />
|
||||
<package id="UnitsNet.nanoFramework.ElectricCurrent" version="4.102.0" targetFramework="netnanoframework10" />
|
||||
<package id="UnitsNet.nanoFramework.Power" version="4.102.0" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Diagnostics.Stopwatch" version="1.0.160" targetFramework="netnanoframework10" />
|
||||
<package id="Nerdbank.GitVersioning" version="3.4.194" developmentDependency="true" targetFramework="netnanoframework10" />
|
||||
</packages>
|
|
@ -20,14 +20,46 @@
|
|||
</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>
|
||||
<Reference Include="mscorlib, Version=1.10.5.4, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.CoreLibrary.1.10.5\lib\mscorlib.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="nanoFramework.Hardware.Esp32, Version=1.3.3.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.Hardware.Esp32.1.3.3\lib\nanoFramework.Hardware.Esp32.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="nanoFramework.Runtime.Events, Version=1.9.1.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.Runtime.Events.1.9.1\lib\nanoFramework.Runtime.Events.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.I2c">
|
||||
<HintPath>..\packages\nanoFramework.System.Device.I2c.1.0.1-preview.33\lib\System.Device.I2c.dll</HintPath>
|
||||
<HintPath>..\packages\nanoFramework.System.Device.I2c.1.0.1\lib\System.Device.I2c.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.Model">
|
||||
<HintPath>..\packages\nanoFramework.System.Device.Model.1.0.176\lib\System.Device.Model.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Buffers.Binary.BinaryPrimitives">
|
||||
<HintPath>..\packages\nanoFramework.System.Buffers.Binary.BinaryPrimitives.1.0.160\lib\System.Buffers.Binary.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnitsNet.ElectricPotential">
|
||||
<HintPath>..\packages\UnitsNet.nanoFramework.ElectricPotential.4.102.0\lib\UnitsNet.ElectricPotential.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnitsNet.ElectricCurrent">
|
||||
<HintPath>..\packages\UnitsNet.nanoFramework.ElectricCurrent.4.102.0\lib\UnitsNet.ElectricCurrent.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnitsNet.Power">
|
||||
<HintPath>..\packages\UnitsNet.nanoFramework.Power.4.102.0\lib\UnitsNet.Power.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<!-- INSERT NEW REFERENCES HERE -->
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
@ -38,12 +70,14 @@
|
|||
<Compile Include="*.cs" />
|
||||
<None Include="*.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ina219.nfproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
|
||||
<Import Project="..\..\src\System.Runtime.CompilerService\System.Runtime.CompilerService.projitems" Label="Shared" />
|
||||
<ProjectExtensions>
|
||||
<ProjectCapabilities>
|
||||
<ProjectConfigurationsDeclaredAsItems />
|
||||
</ProjectCapabilities>
|
||||
</ProjectExtensions>
|
||||
<!-- INSERT NBGV IMPORT HERE -->
|
||||
</Project>
|
||||
</Project>
|
|
@ -6,12 +6,19 @@ using System.Threading;
|
|||
using System.Device.I2c;
|
||||
using Iot.Device;
|
||||
using Iot.Device.Adc;
|
||||
using System.Diagnostics;
|
||||
using nanoFramework.Hardware.Esp32;
|
||||
|
||||
const byte Adafruit_Ina219_I2cAddress = 0x40;
|
||||
const byte Adafruit_Ina219_I2cBus = 0x1;
|
||||
const byte Ina219_I2cAddress = 0x40;
|
||||
const byte Ina219_I2cBus = 0x1;
|
||||
|
||||
|
||||
// Must specify pin functions on ESP32, not needed for most other boards
|
||||
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
|
||||
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);
|
||||
|
||||
// create an INA219 device on I2C bus 1 addressing channel 64
|
||||
using Ina219 device = new(new I2cConnectionSettings(Adafruit_Ina219_I2cBus, Adafruit_Ina219_I2cAddress));
|
||||
using Ina219 device = new(new I2cConnectionSettings(Ina219_I2cBus, Ina219_I2cAddress));
|
||||
// reset the device
|
||||
device.Reset();
|
||||
|
||||
|
@ -23,6 +30,6 @@ device.SetCalibration(33574, 12.2e-6f);
|
|||
while (true)
|
||||
{
|
||||
// write out the current values from the INA219 device.
|
||||
Debug.WriteLine($"Bus Voltage {device.ReadBusVoltage()} Shunt Voltage {device.ReadShuntVoltage().Millivolts}mV Current {device.ReadCurrent()} Power {device.ReadPower()}");
|
||||
Debug.WriteLine($"Bus Voltage {device.ReadBusVoltage().Volts} Shunt Voltage {device.ReadShuntVoltage().Millivolts}mV Current {device.ReadCurrent().Value} Power {device.ReadPower().Watts}");
|
||||
Thread.Sleep(1000);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="nanoFramework.CoreLibrary" version="1.10.5" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.Hardware.Esp32" version="1.3.3" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.Runtime.Events" version="1.9.1" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Buffers.Binary.BinaryPrimitives" version="1.0.160" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.I2c" version="1.0.1" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.Model" version="1.0.176" targetFramework="netnanoframework10" />
|
||||
<package id="UnitsNet.nanoFramework.ElectricCurrent" version="4.102.0" targetFramework="netnanoframework10" />
|
||||
<package id="UnitsNet.nanoFramework.ElectricPotential" version="4.102.0" targetFramework="netnanoframework10" />
|
||||
<package id="UnitsNet.nanoFramework.Power" version="4.102.0" targetFramework="netnanoframework10" />
|
||||
</packages>
|
Двоичные данные
src/devices_generated/Ina219/Ina219.Sample.fzz
Двоичные данные
src/devices_generated/Ina219/Ina219.Sample.fzz
Двоичный файл не отображается.
Двоичные данные
src/devices_generated/Ina219/Ina219.Sample_bb.png
Двоичные данные
src/devices_generated/Ina219/Ina219.Sample_bb.png
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 238 KiB |
|
@ -1,53 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{0D478BAB-AFEA-4AF1-866C-E3AC32E11C5A}"
|
||||
EndProject
|
||||
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Ina219.Samples", "samples\Ina219.Samples.nfproj", "{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}"
|
||||
EndProject
|
||||
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Ina219", "Ina219.nfproj", "{1398DC14-97F0-4048-965A-CCB3D44BFE06}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Release|x64.Build.0 = Release|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6}.Release|x86.Build.0 = Release|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Release|x64.Build.0 = Release|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{1398DC14-97F0-4048-965A-CCB3D44BFE06}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{D9FEFE08-18E7-458A-8ECC-73A8D1E078F6} = {0D478BAB-AFEA-4AF1-866C-E3AC32E11C5A}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,8 +0,0 @@
|
|||
<?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.ElectricPotential" version="4.92.0" targetFramework="netnanoframework10" />
|
||||
<package id="UnitsNet.nanoFramework.ElectricCurrent" version="4.92.0" targetFramework="netnanoframework10" />
|
||||
<package id="Nerdbank.GitVersioning" version="3.4.194" developmentDependency="true" targetFramework="netnanoframework10" />
|
||||
</packages>
|
|
@ -1,5 +0,0 @@
|
|||
<?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" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче