Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RB3/CM3 Support to all libraries, nuget added#93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
JTrotta wants to merge19 commits intoraspberry-sharp:master
base:master
Choose a base branch
Loading
fromJTrotta:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
f0a9983
RPi3
JTrottaJun 5, 2017
94233f2
Added try catch
JTrottaJun 5, 2017
88fb1ab
Added support for RPi3
JTrottaJun 5, 2017
37f1e2a
Adding RP3/CM3 support
JTrottaSep 13, 2017
4951cc6
Addeb to nuget
JTrottaSep 13, 2017
27de18d
Updated file version
JTrottaSep 13, 2017
1b53c71
Refactoring
JTrottaSep 22, 2017
527be4d
I2c Repeated Start now works
JTrottaOct 3, 2017
2aa9e70
Some updates
JTrottaNov 6, 2017
6eb0a0f
Added HTU21DF driver
ChrisDodgeRRNov 7, 2017
e90ec57
Merge pull request #1 from JTrotta/HTU21DF-Driver
JTrottaNov 7, 2017
769df7d
Update DhtConnection.cs
lucagraziani82Jan 12, 2018
37b7048
Update Dht11Connection.cs
lucagraziani82Jan 12, 2018
6f80418
Update Dht22Connection.cs
lucagraziani82Jan 12, 2018
53159dd
Merge pull request #3 from lucagraziani82/patch-1
JTrottaJan 12, 2018
029f90c
Merge pull request #4 from lucagraziani82/patch-2
JTrottaJan 12, 2018
10c91a0
Merge pull request #5 from lucagraziani82/patch-3
JTrottaJan 12, 2018
259bd4c
Update README.md
JTrottaAug 7, 2018
ac1c448
Update README.md
JTrottaAug 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,7 @@ TestResults
**.suo
**.sdf
*.sln.docstates
.vs/*

# resharper
/_[Rr]e[Ss]harper.*
Expand Down
Binary file modifiedIcon.png
View file
Open in desktop
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
Raspberry# IO
This project is discontinued, try https://github.com/JTrotta/RaspberrySharp

Raspberry# IO
=============

See the **[Raspberry\# IO Wiki](https://github.com/raspberry-sharp/raspberry-sharp-io/wiki)** for full documentation and samples.
Expand All@@ -23,7 +25,7 @@ Features

### Raspberry.IO.GeneralPurpose
Raspberry.IO.GeneralPurpose provides a convenient way to use Raspberry Pi GPIO pins, while using .NET concepts, syntax and case.
You can easily add a reference to it in your Visual Studio projects using the **[Raspberry.IO.GeneralPurpose Nuget](https://www.nuget.org/packages/Raspberry.IO.GeneralPurpose)**.
You can easily add a reference to it in your Visual Studio projects using the **[Raspberry.IO.GeneralPurpose Nuget](https://www.nuget.org/packages/Raspberry.IO.GeneralPurpose3)**.

It currently support the following features:

Expand All@@ -43,12 +45,15 @@ High-level:
+ **High-level behaviors** for output pins, including *blink*, *pattern* and *chaser*

### Raspberry.IO.SerialPeripheralInterface
You can easily add a reference to it in your Visual Studio projects using the **[Raspberry.IO.Raspberry.IO.SerialPeripheralInterface Nuget](https://www.nuget.org/packages/Raspberry.IO.SerialPeripheralInterface3)**.


+ Preliminary support for SPI through Raspberry.IO.SerialPeripheralInterface assembly
+ Includes SPI samples for MCP3008 ADC and MCP4822 DAC
+ Includes support for Linux's kernel SPI module driver spi-bcm2708 (/dev/spidev0.0)

### Raspberry.IO.InterIntegratedCircuit
You can easily add a reference to it in your Visual Studio projects using the **[Raspberry.IO.Raspberry.IO.InterIntegratedCircuit Nuget](https://www.nuget.org/packages/Raspberry.IO.InterIntegratedCircuit3)**.

+ Preliminary support for I2C through Raspberry.IO.InterIntegratedCircuit assembly
+ Includes I2C sample for MCP23017 I/O expander
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
using System;
using System.Globalization;

namespace Raspberry.IO.Components.Sensors.Temperature.Dht
namespace Raspberry.IO.Components
{
public class InvalidChecksumException : Exception
{
Expand Down
63 changes: 51 additions & 12 deletionsRaspberry.IO.Components/Raspberry.IO.Components.csproj
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,21 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All@@ -30,21 +45,23 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Raspberry.System, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)packages\Raspberry.System.2.1\lib\net40\Raspberry.System.dll</HintPath>
<Reference Include="Common.Logging, Version=3.4.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.3.4.1\lib\net40\Common.Logging.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Common.Logging.Core, Version=3.4.1.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
<HintPath>..\packages\Common.Logging.Core.3.4.1\lib\net40\Common.Logging.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Raspberry.System, Version=3.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Raspberry.System3.3.1.1\lib\net40\Raspberry.System.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Configuration" />
<Reference Include="Common.Logging.Core">
<HintPath>$(SolutionDir)packages\Common.Logging.Core.3.3.1\lib\net40\Common.Logging.Core.dll</HintPath>
</Reference>
<Reference Include="Common.Logging">
<HintPath>$(SolutionDir)packages\Common.Logging.3.3.1\lib\net40\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="UnitsNet, Version=3.46.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)packages\UnitsNet.3.46.1\lib\net35\UnitsNet.dll</HintPath>
<Reference Include="UnitsNet, Version=3.77.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\UnitsNet.3.77.0\lib\net35\UnitsNet.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
Expand DownExpand Up@@ -127,14 +144,15 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sensors\Distance\HcSr04\HcSr04Connection.cs" />
<Compile Include="Sensors\Distance\HcSr04\Units.cs" />
<Compile Include="Sensors\Humidity\Htu21df\Htu21dfConnection.cs" />
<Compile Include="Sensors\Pressure\Bmp085\Bmp085Data.cs" />
<Compile Include="Sensors\Pressure\Bmp085\Bmp085I2cConnectionExtensionMethods.cs" />
<Compile Include="Sensors\Pressure\Bmp085\Bmp085Precision.cs" />
<Compile Include="Sensors\Temperature\Dht\Dht11Connection.cs" />
<Compile Include="Sensors\Temperature\Dht\Dht22Connection.cs" />
<Compile Include="Sensors\Temperature\Dht\DhtConnection.cs" />
<Compile Include="Sensors\Temperature\Dht\DhtData.cs" />
<Compile Include="Sensors\Temperature\Dht\InvalidChecksumException.cs" />
<Compile Include="InvalidChecksumException.cs" />
<Compile Include="Sensors\Temperature\Ds18b20\Ds18b20Connection.cs" />
<Compile Include="Sensors\VariableResistiveDividerConnection.cs" />
<Compile Include="Sensors\Temperature\Tmp36\Tmp36Connection.cs" />
Expand DownExpand Up@@ -181,7 +199,28 @@
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.4.5">
<Visible>False</Visible>
<ProductName>Windows Installer 4.5</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
using System;
using System.Threading;
using Raspberry.IO.Components.Sensors.Temperature.Dht;
using Raspberry.IO.InterIntegratedCircuit;

namespace Raspberry.IO.Components.Sensors.Humidity.Htu21df
{
/// <summary>
/// Connection to the HTU21D-F Adafruit humidity and temperature breakout board.
/// </summary>
/// <remarks>See <see cref="https://www.adafruit.com/datasheets/1899_HTU21D.pdf"/> for more information.</remarks>///
public class Htu21dfConnection
{
#region Helpers

public enum I2cDefs : byte
{
HTU21DF_I2CADDR = 0x40,
HTU21DF_READTEMP = 0xE3,
HTU21DF_READHUM = 0xE5,
HTU21DF_READTEMP_NOHOLDMASTER = 0xF3,
HTU21DF_READHUM_NOHOLDMASTER = 0xF5,
HTU21DF_WRITEREG = 0xE6,
HTU21DF_READREG = 0xE7,
HTU21DF_RESET = 0xFE,
}

public enum I2cReadMode
{
/// <summary>
/// Default. In this mode, the SCK line is blocked during the measurement process. When measurement is complete
/// the sensor indicates by releasing SCK and the read can continue.
/// </summary>
HoldMaster,

/// <summary>
/// The sensor does not hold SCK so other I2C comms can take place on the bus. The MCU (R-Pi) has to then
/// poll for the data. NOT CURRENTLY SUPPORTED.
/// </summary>
NoHoldMaster,
}

#endregion

#region Fields

private readonly I2cDeviceConnection connection;

#endregion

#region Instance Management

/// <summary>
/// Initializes a new instance of the <see cref="Htu21dfConnection"/> class.
/// </summary>
/// <param name="connection">The connection.</param>
public Htu21dfConnection( I2cDeviceConnection connection )
{
this.connection = connection;
ReadMode = I2cReadMode.HoldMaster;
}

#endregion

#region Methods

public I2cReadMode ReadMode { get; set; }

/// <summary>
/// Init's the sensor and checks its status is OK.
/// </summary>
public void Begin()
{
Reset();

connection.WriteByte( (byte) I2cDefs.HTU21DF_READREG );
var status = connection.ReadByte();
if ( status != 0x02 )
{
throw new Exception( $"Status following reset should be 0x02. Have {status}" );
}
}

/// <summary>
/// Resets the sensor by power cycling. Takes about 15ms.
/// </summary>
private void Reset()
{
connection.WriteByte((byte)I2cDefs.HTU21DF_RESET);
Thread.Sleep(15);
}

/// <summary>
/// Reads the temperature value from the sensor.
/// </summary>
/// <returns>Temperature in degrees Centigrade.</returns>
public double ReadTemperature()
{
if ( ReadMode == I2cReadMode.NoHoldMaster )
{
throw new NotSupportedException( "No-Hold-Master read mode not supported." );
}

connection.WriteByte( (byte) I2cDefs.HTU21DF_READTEMP );

// Add delay between request and actual read
Thread.Sleep( 50 );

// Read 3 bytes; 2 bytes temp data and one byte checksum.
var readBytes = connection.Read( 3 );
CheckCrc( readBytes );

// Get data value from bytes 0 and 1.
var tVal = ( readBytes[0] << 8 ) + readBytes[1];

// Compute temp using formula from datasheet.
return ( ( tVal * 175.72 ) / 65536 ) - 46.85;
}

/// <summary>
/// Reads the humidity value from the sensor.
/// </summary>
/// <returns>The relative humidity value as a percentage.</returns>
public double ReadHumidity()
{
if (ReadMode == I2cReadMode.NoHoldMaster)
{
throw new NotSupportedException("No-Hold-Master read mode not supported.");
}

connection.WriteByte((byte)I2cDefs.HTU21DF_READHUM);

// Add delay between request and actual read
Thread.Sleep( 50 );

// Read 3 bytes; 2 bytes temp data and one byte checksum.
var readBytes = connection.Read( 3 );
CheckCrc( readBytes );

// Get data value from bytes 0 and 1.
var hVal = ( readBytes[0] << 8 ) + readBytes[1];

// Compute temp using formula from datasheet.
return ( ( (double)hVal * 125 ) / 65536 ) - 6;
}

/// <summary>
/// Calculate the CRC checksum. The result should be zero.
/// Thanks to the IoT-Playground - https://github.com/iot-playground.
/// </summary>
public static void CheckCrc(byte[] readData)
{
// Test cases from datasheet:
// sensor value = 0xDC, checkvalue is 0x79. readData = 0x00DC79.
// message = 0x683A, checkvalue is 0x7C. readData = 0x683A7C
// message = 0x4E85, checkvalue is 0x6B. readData = 0x45856B

// Create a 32-bit value with bytes of {0, val-msb, val-lsb, checksum}
var remainder = (uint) ( ( readData[0] << 16 ) + ( readData[1] << 8 ) + readData[2] );

// This is the x^8 + x^5 + x^4 + 1 polynomial (100110001), but shifted up to start at the left-hand
// side of the 24-bit value.
uint divisor = 0x988000;

for ( var i = 0; i < 16; i++ )
{
if ( (remainder & (1<<(23-i))) != 0 )
{
remainder ^= divisor;
}

divisor >>= 1;
}

if ( remainder != 0 )
{
throw new InvalidChecksumException( 0x00, remainder );
}
}

#endregion
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
#region References

#region References

using System;
using UnitsNet;
Expand DownExpand Up@@ -34,6 +35,13 @@ protected override TimeSpan WakeupInterval
{
get { return TimeSpan.FromMilliseconds(18); }
}

protected override TimeSpan HostReleaseBusInterval
{
get { throw new ArgumentException("DHT11 sensor does not have the host release time"); }
}

protected override bool HaveHostReleaseBus => false;

protected override DhtData GetDhtData(int temperatureValue, int humidityValue)
{
Expand All@@ -46,4 +54,4 @@ protected override DhtData GetDhtData(int temperatureValue, int humidityValue)

#endregion
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,13 @@ protected override TimeSpan WakeupInterval
{
get { return TimeSpan.FromMilliseconds(1); }
}

protected override TimeSpan HostReleaseBusInterval
{
get { return new TimeSpan(10 * 20); }
}

protected override bool HaveHostReleaseBus => true;

protected override DhtData GetDhtData(int temperatureValue, int humidityValue)
{
Expand All@@ -46,4 +53,4 @@ protected override DhtData GetDhtData(int temperatureValue, int humidityValue)

#endregion
}
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp