Skip to content

Commit 757689c

Browse files
torbaczEllerbach
andauthored
[Vl6180x] Add new binding for distance sensor (#1222)
Co-authored-by: Laurent Ellerbach <[email protected]>
1 parent 45bdffe commit 757689c

File tree

17 files changed

+769
-0
lines changed

17 files changed

+769
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Reflection;
5+
using System.Runtime.CompilerServices;
6+
using System.Runtime.InteropServices;
7+
8+
[assembly: AssemblyTitle("Iot.Device.Vl6180X")]
9+
[assembly: AssemblyCompany("nanoFramework Contributors")]
10+
[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")]
11+
12+
[assembly: ComVisible(false)]

devices/Vl6180X/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Vl6180X - distance sensor
2+
3+
The Vl6180X sensor is a Time-to-Flight sensor measuring precisely distances. The sensor allows you to get precise short distance measurement (from 5 millimeters to 2 meters) as well as long distance measurement (up to 8 meters but with a decreased precision). This sensor is a laser ranging sensor. It is using laser pulses to measure the distances.
4+
5+
## Documentation
6+
7+
**Vl6180X** [datasheet](https://www.st.com/resource/en/datasheet/vl6180x.pdf)
8+
9+
## Usage
10+
11+
**Important**: make sure you properly setup the I2C pins especially for ESP32 before creating the `I2cDevice`, make sure you install the `nanoFramework.Hardware.ESP32 nuget`:
12+
13+
```csharp
14+
// when connecting to an ESP32 device, need to configure the I2C GPIOs used for the bus
15+
Configuration.SetPinFunction(11, DeviceFunction.I2C1_DATA);
16+
Configuration.SetPinFunction(10, DeviceFunction.I2C1_CLOCK);
17+
18+
using VL6180X sensor = new(I2cDevice.Create(new I2cConnectionSettings(1, VL6180X.DefaultI2cAddress)));
19+
sensor.Init();
20+
while (true)
21+
{
22+
var distance = sensor.ReadRange();
23+
Console.WriteLine($"Distance: {distance.Centimeters} cm.");
24+
Thread.Sleep(500);
25+
}
26+
```
27+
28+
## Not implemented
29+
30+
- ALS (ambient light sensor
31+
- Range scaling
32+
- Range continuous measurement
33+
- I2C Address set
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Iot.Device.VL6180X
5+
{
6+
internal enum RegisterAddresses : ushort
7+
{
8+
IDENTIFICATION__MODEL_ID = 0x000,
9+
IDENTIFICATION__MODEL_REV_MAJOR = 0x001,
10+
IDENTIFICATION__MODEL_REV_MINOR = 0x002,
11+
IDENTIFICATION__MODULE_REV_MAJOR = 0x003,
12+
IDENTIFICATION__MODULE_REV_MINOR = 0x004,
13+
IDENTIFICATION__DATE_HI = 0x006,
14+
IDENTIFICATION__DATE_LO = 0x007,
15+
IDENTIFICATION__TIME = 0x008, // 16-bit
16+
SYSTEM__MODE_GPIO0 = 0x010,
17+
SYSTEM__MODE_GPIO1 = 0x011,
18+
SYSTEM__HISTORY_CTRL = 0x012,
19+
SYSTEM__INTERRUPT_CONFIG_GPIO = 0x014,
20+
SYSTEM__INTERRUPT_CLEAR = 0x015,
21+
SYSTEM__FRESH_OUT_OF_RESET = 0x016,
22+
SYSTEM__GROUPED_PARAMETER_HOLD = 0x017,
23+
SYSRANGE__START = 0x018,
24+
SYSRANGE__THRESH_HIGH = 0x019,
25+
SYSRANGE__THRESH_LOW = 0x01A,
26+
SYSRANGE__INTERMEASUREMENT_PERIOD = 0x01B,
27+
SYSRANGE__MAX_CONVERGENCE_TIME = 0x01C,
28+
SYSRANGE__CROSSTALK_COMPENSATION_RATE = 0x01E, // 16-bit
29+
SYSRANGE__CROSSTALK_VALID_HEIGHT = 0x021,
30+
SYSRANGE__EARLY_CONVERGENCE_ESTIMATE = 0x022, // 16-bit
31+
SYSRANGE__PART_TO_PART_RANGE_OFFSET = 0x024,
32+
SYSRANGE__RANGE_IGNORE_VALID_HEIGHT = 0x025,
33+
SYSRANGE__RANGE_IGNORE_THRESHOLD = 0x026, // 16-bit
34+
SYSRANGE__MAX_AMBIENT_LEVEL_MULT = 0x02C,
35+
SYSRANGE__RANGE_CHECK_ENABLES = 0x02D,
36+
SYSRANGE__VHV_RECALIBRATE = 0x02E,
37+
SYSRANGE__VHV_REPEAT_RATE = 0x031,
38+
SYSALS__START = 0x038,
39+
SYSALS__THRESH_HIGH = 0x03A,
40+
SYSALS__THRESH_LOW = 0x03C,
41+
SYSALS__INTERMEASUREMENT_PERIOD = 0x03E,
42+
SYSALS__ANALOGUE_GAIN = 0x03F,
43+
SYSALS__INTEGRATION_PERIOD = 0x040,
44+
RESULT__RANGE_STATUS = 0x04D,
45+
RESULT__ALS_STATUS = 0x04E,
46+
RESULT__INTERRUPT_STATUS_GPIO = 0x04F,
47+
RESULT__ALS_VAL = 0x050, // 16-bit
48+
RESULT__HISTORY_BUFFER_0 = 0x052, // 16-bit
49+
RESULT__HISTORY_BUFFER_1 = 0x054, // 16-bit
50+
RESULT__HISTORY_BUFFER_2 = 0x056, // 16-bit
51+
RESULT__HISTORY_BUFFER_3 = 0x058, // 16-bit
52+
RESULT__HISTORY_BUFFER_4 = 0x05A, // 16-bit
53+
RESULT__HISTORY_BUFFER_5 = 0x05C, // 16-bit
54+
RESULT__HISTORY_BUFFER_6 = 0x05E, // 16-bit
55+
RESULT__HISTORY_BUFFER_7 = 0x060, // 16-bit
56+
RESULT__RANGE_VAL = 0x062,
57+
RESULT__RANGE_RAW = 0x064,
58+
RESULT__RANGE_RETURN_RATE = 0x066, // 16-bit
59+
RESULT__RANGE_REFERENCE_RATE = 0x068, // 16-bit
60+
RESULT__RANGE_RETURN_SIGNAL_COUNT = 0x06C, // 32-bit
61+
RESULT__RANGE_REFERENCE_SIGNAL_COUNT = 0x070, // 32-bit
62+
RESULT__RANGE_RETURN_AMB_COUNT = 0x074, // 32-bit
63+
RESULT__RANGE_REFERENCE_AMB_COUNT = 0x078, // 32-bit
64+
RESULT__RANGE_RETURN_CONV_TIME = 0x07C, // 32-bit
65+
RESULT__RANGE_REFERENCE_CONV_TIME = 0x080, // 32-bit
66+
RANGE_SCALER = 0x096, // 16-bit - see STSW-IMG003 core/inc/vl6180x_def.h
67+
READOUT__AVERAGING_SAMPLE_PERIOD = 0x10A,
68+
FIRMWARE__BOOTUP = 0x119,
69+
FIRMWARE__RESULT_SCALER = 0x120,
70+
I2C_SLAVE__DEVICE_ADDRESS = 0x212,
71+
INTERLEAVED_MODE__ENABLE = 0x2A3,
72+
}
73+
}

devices/Vl6180X/Settings.StyleCop

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<StyleCopSettings Version="105">
2+
<Analyzers>
3+
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
4+
<Rules>
5+
<Rule Name="FileHeaderMustContainFileName">
6+
<RuleSettings>
7+
<BooleanProperty Name="Enabled">False</BooleanProperty>
8+
</RuleSettings>
9+
</Rule>
10+
<Rule Name="FileHeaderMustHaveValidCompanyText">
11+
<RuleSettings>
12+
<BooleanProperty Name="Enabled">False</BooleanProperty>
13+
</RuleSettings>
14+
</Rule>
15+
<Rule Name="FileHeaderFileNameDocumentationMustMatchTypeName">
16+
<RuleSettings>
17+
<BooleanProperty Name="Enabled">False</BooleanProperty>
18+
</RuleSettings>
19+
</Rule>
20+
<Rule Name="PropertyDocumentationMustHaveValueText">
21+
<RuleSettings>
22+
<BooleanProperty Name="Enabled">True</BooleanProperty>
23+
</RuleSettings>
24+
</Rule>
25+
<Rule Name="DocumentationTextMustBeginWithACapitalLetter">
26+
<RuleSettings>
27+
<BooleanProperty Name="Enabled">True</BooleanProperty>
28+
</RuleSettings>
29+
</Rule>
30+
<Rule Name="DocumentationTextMustEndWithAPeriod">
31+
<RuleSettings>
32+
<BooleanProperty Name="Enabled">True</BooleanProperty>
33+
</RuleSettings>
34+
</Rule>
35+
<Rule Name="FileHeaderMustShowCopyright">
36+
<RuleSettings>
37+
<BooleanProperty Name="Enabled">False</BooleanProperty>
38+
</RuleSettings>
39+
</Rule>
40+
<Rule Name="FileHeaderMustHaveCopyrightText">
41+
<RuleSettings>
42+
<BooleanProperty Name="Enabled">False</BooleanProperty>
43+
</RuleSettings>
44+
</Rule>
45+
<Rule Name="ElementDocumentationMustBeSpelledCorrectly">
46+
<RuleSettings>
47+
<BooleanProperty Name="Enabled">False</BooleanProperty>
48+
</RuleSettings>
49+
</Rule>
50+
<Rule Name="DocumentationTextMustContainWhitespace">
51+
<RuleSettings>
52+
<BooleanProperty Name="Enabled">False</BooleanProperty>
53+
</RuleSettings>
54+
</Rule>
55+
</Rules>
56+
<AnalyzerSettings>
57+
<BooleanProperty Name="IgnorePrivates">True</BooleanProperty>
58+
<BooleanProperty Name="IgnoreInternals">True</BooleanProperty>
59+
</AnalyzerSettings>
60+
</Analyzer>
61+
<Analyzer AnalyzerId="StyleCop.CSharp.ReadabilityRules">
62+
<Rules>
63+
<Rule Name="PrefixLocalCallsWithThis">
64+
<RuleSettings>
65+
<BooleanProperty Name="Enabled">False</BooleanProperty>
66+
</RuleSettings>
67+
</Rule>
68+
<Rule Name="PrefixCallsCorrectly">
69+
<RuleSettings>
70+
<BooleanProperty Name="Enabled">False</BooleanProperty>
71+
</RuleSettings>
72+
</Rule>
73+
</Rules>
74+
<AnalyzerSettings />
75+
</Analyzer>
76+
<Analyzer AnalyzerId="StyleCop.CSharp.OrderingRules">
77+
<Rules>
78+
<Rule Name="UsingDirectivesMustBePlacedWithinNamespace">
79+
<RuleSettings>
80+
<BooleanProperty Name="Enabled">False</BooleanProperty>
81+
</RuleSettings>
82+
</Rule>
83+
<Rule Name="ElementsMustAppearInTheCorrectOrder">
84+
<RuleSettings>
85+
<BooleanProperty Name="Enabled">False</BooleanProperty>
86+
</RuleSettings>
87+
</Rule>
88+
<Rule Name="ElementsMustBeOrderedByAccess">
89+
<RuleSettings>
90+
<BooleanProperty Name="Enabled">False</BooleanProperty>
91+
</RuleSettings>
92+
</Rule>
93+
</Rules>
94+
<AnalyzerSettings />
95+
</Analyzer>
96+
<Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
97+
<Rules>
98+
<Rule Name="FieldNamesMustNotBeginWithUnderscore">
99+
<RuleSettings>
100+
<BooleanProperty Name="Enabled">False</BooleanProperty>
101+
</RuleSettings>
102+
</Rule>
103+
<Rule Name="FieldNamesMustNotUseHungarianNotation">
104+
<RuleSettings>
105+
<BooleanProperty Name="Enabled">False</BooleanProperty>
106+
</RuleSettings>
107+
</Rule>
108+
</Rules>
109+
<AnalyzerSettings />
110+
</Analyzer>
111+
</Analyzers>
112+
</StyleCopSettings>

devices/Vl6180X/VL6180X.nuspec

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
3+
<metadata>
4+
<id>nanoFramework.Iot.Device.Vl6180X</id>
5+
<version>$version$</version>
6+
<title>nanoFramework.Iot.Device.Vl6180X</title>
7+
<authors>nanoframework</authors>
8+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
9+
<license type="file">LICENSE.md</license>
10+
<releaseNotes>
11+
</releaseNotes>
12+
<readme>docs\README.md</readme>
13+
<developmentDependency>false</developmentDependency>
14+
<projectUrl>https://github.com/nanoframework/nanoFramework.IoT.Device</projectUrl>
15+
<icon>images\nf-logo.png</icon>
16+
<repository type="git" url="https://github.com/nanoframework/nanoFramework.IoT.Device" commit="$commit$" />
17+
<copyright>Copyright (c) .NET Foundation and Contributors</copyright>
18+
<description>This package includes the .NET IoT Core binding Iot.Device.Vl6180X for .NET nanoFramework C# projects.</description>
19+
<summary>Iot.Device.Vl6180X assembly for .NET nanoFramework C# projects</summary>
20+
<tags>nanoFramework C# csharp netmf netnf Iot.Device.Vl6180X</tags>
21+
<dependencies>
22+
<dependency id="nanoFramework.CoreLibrary" version="1.15.5" />
23+
<dependency id="nanoFramework.Runtime.Events" version="1.11.18" />
24+
<dependency id="nanoFramework.Runtime.Native" version="1.7.1" />
25+
<dependency id="nanoFramework.System.Buffers.Binary.BinaryPrimitives" version="1.2.699" />
26+
<dependency id="nanoFramework.System.Device.Gpio" version="1.1.41" />
27+
<dependency id="nanoFramework.System.Device.I2c" version="1.1.16" />
28+
<dependency id="UnitsNet.nanoFramework.Length" version="5.65.0" />
29+
</dependencies>
30+
</metadata>
31+
<files>
32+
<file src="bin\Release\Iot.Device.Vl6180X.dll" target="lib\Iot.Device.Vl6180X.dll" />
33+
<file src="bin\Release\Iot.Device.Vl6180X.pdb" target="lib\Iot.Device.Vl6180X.pdb" />
34+
<file src="bin\Release\Iot.Device.Vl6180X.pdbx" target="lib\Iot.Device.Vl6180X.pdbx" />
35+
<file src="bin\Release\Iot.Device.Vl6180X.pe" target="lib\Iot.Device.Vl6180X.pe" />
36+
<file src="bin\Release\Iot.Device.Vl6180X.xml" target="lib\Iot.Device.Vl6180X.xml" />
37+
<file src="README.md" target="docs\" />
38+
<file src="..\..\assets\nf-logo.png" target="images" />
39+
<file src="..\..\LICENSE.md" target="" />
40+
</files>
41+
</package>

devices/Vl6180X/VL6180X.sln

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.12.35527.113
4+
MinimumVisualStudioVersion = 15.0.26124.0
5+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{7C2F11ED-8E84-4F3B-AC2E-3167BBDC303A}"
6+
EndProject
7+
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Vl6180X", "Vl6180X.nfproj", "{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}"
8+
EndProject
9+
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "Vl6180x.sample", "samples\Vl6180x.sample\Vl6180x.sample.nfproj", "{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}"
10+
EndProject
11+
Global
12+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
13+
Debug|Any CPU = Debug|Any CPU
14+
Debug|x64 = Debug|x64
15+
Debug|x86 = Debug|x86
16+
Release|Any CPU = Release|Any CPU
17+
Release|x64 = Release|x64
18+
Release|x86 = Release|x86
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
24+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Debug|x64.ActiveCfg = Debug|Any CPU
25+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Debug|x64.Build.0 = Debug|Any CPU
26+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Debug|x64.Deploy.0 = Debug|Any CPU
27+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Debug|x86.ActiveCfg = Debug|Any CPU
28+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Debug|x86.Build.0 = Debug|Any CPU
29+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Debug|x86.Deploy.0 = Debug|Any CPU
30+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
31+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Release|Any CPU.Deploy.0 = Release|Any CPU
33+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Release|x64.ActiveCfg = Release|Any CPU
34+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Release|x64.Build.0 = Release|Any CPU
35+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Release|x64.Deploy.0 = Release|Any CPU
36+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Release|x86.ActiveCfg = Release|Any CPU
37+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Release|x86.Build.0 = Release|Any CPU
38+
{43F4ECB2-B009-EB94-DDB7-C10931BB67A3}.Release|x86.Deploy.0 = Release|Any CPU
39+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Debug|Any CPU.Build.0 = Debug|Any CPU
41+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
42+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Debug|x64.ActiveCfg = Debug|Any CPU
43+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Debug|x64.Build.0 = Debug|Any CPU
44+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Debug|x64.Deploy.0 = Debug|Any CPU
45+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Debug|x86.ActiveCfg = Debug|Any CPU
46+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Debug|x86.Build.0 = Debug|Any CPU
47+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Debug|x86.Deploy.0 = Debug|Any CPU
48+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Release|Any CPU.ActiveCfg = Release|Any CPU
49+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Release|Any CPU.Deploy.0 = Release|Any CPU
51+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Release|x64.ActiveCfg = Release|Any CPU
52+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Release|x64.Build.0 = Release|Any CPU
53+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Release|x64.Deploy.0 = Release|Any CPU
54+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Release|x86.ActiveCfg = Release|Any CPU
55+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Release|x86.Build.0 = Release|Any CPU
56+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E}.Release|x86.Deploy.0 = Release|Any CPU
57+
EndGlobalSection
58+
GlobalSection(SolutionProperties) = preSolution
59+
HideSolutionNode = FALSE
60+
EndGlobalSection
61+
GlobalSection(NestedProjects) = preSolution
62+
{A6C96750-E9DE-4F27-99EF-D5C6BB0C866E} = {7C2F11ED-8E84-4F3B-AC2E-3167BBDC303A}
63+
EndGlobalSection
64+
GlobalSection(ExtensibilityGlobals) = postSolution
65+
SolutionGuid = {64D5FD74-E6BF-4033-8AC2-5CD72E597400}
66+
EndGlobalSection
67+
EndGlobal

0 commit comments

Comments
 (0)