DNETCoreGPIO 1.3.3

dotnet add package DNETCoreGPIO --version 1.3.3
NuGet\Install-Package DNETCoreGPIO -Version 1.3.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DNETCoreGPIO" Version="1.3.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DNETCoreGPIO --version 1.3.3
#r "nuget: DNETCoreGPIO, 1.3.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DNETCoreGPIO as a Cake Addin
#addin nuget:?package=DNETCoreGPIO&version=1.3.3

// Install DNETCoreGPIO as a Cake Tool
#tool nuget:?package=DNETCoreGPIO&version=1.3.3

DNETCoreGPIO

A .NET library then can be used directly with a .NET console app app to run on the RPi. Works with both Raspian (Debian).
Uses System.Devices.GPIO and Iot.Device.Bindings Nuget packages.

Usage

Create a .NET Console app:
Run dotnet new console

Add the library as a Nuget package
Run dotnet add package DNETCoreGPIO --version 1.y.x
NB: Use the current version, in place of 1.y.x,check at https://www.nuget.org/packages/DNETCoreGPIO/
Can use * to get latest.

Change the 7th line in Program.cs as below:


using System.Threading.Tasks;

namespace ConsoleGPIOApp
{
	class Program
	{
		static aync Task Main(string[] args)
		{
			await DotNetCoreCoreGPIO.Program.Main(args);
		}
	}
}

NB: if using .NET6.0 Console template you only need a one line file for Program.cs:
DotNetCoreCoreGPIO.Program.Main(args);

Build and run the app with the required first parameter.(See below)

***Based upon samples in the GitHUb Repository: dotnet/iot

New Feature: Can change GPIO mappings as second parameter. eg "17,4,26,22,27,17,19", which is the current settings.
Which map to led,button,dht22,motoren, motorfwd,motorrev,relay respectively.

Parameters

Run the app with one of the following as the first parameter Note possible 2nd parameter for GPIO mappings as above.

  1. Led and Button press
  2. Temperature with BME280 sensor ..2Do
  3. Temperature and Humidity with DHTxx sensor ..2Do
  4. Temperature and Humidity with DHT22 sensor using 1-Wire <
  5. LED driven by Software PWM.
  6. H-Bridge Motor using L293D

Whilst the above run continously or until stopped the following only do a single pass.
These are used by TRIGGERcmd

11/12. Relay On/Off

  1. Temperature and Humidity with DHT22 sensor using 1-Wire.
    Get single value and write to /tmp/temperature.txt on RPi
    See TRIGGERcmd.GetTempDHTxx1Wire()

  2. Temperature Pressure and Humidity with BME280.
    Get single values and write to /tmp/temperature.txt, on RPi

  3. Set LED as per 1.

  4. Clear LED ditto

  5. Toggle LED ditto

The following control the motor as in 6 but as separate commands.

  1. Motor Partial off: Set Fwd and Rev to off
  2. Motor Forward
  3. Motor Reverse
  4. Motor Enable
  5. Motor Disable
  6. Motor Off (Fwd=Rev=En=off)

The following run continously:
30. (2Do) Start sending DHT22 1-Wire Telemetry to Azure IoT Hub. Requires a period (default 10 sec) between readings and DeviceConnectionString.
31. Start sending BME280 Telemetry to Azure IoT Hub. Requires a period (default 10 sec) between readings and DeviceConnectionString.

PS: Can toggle a soleniod with the LED.

Run

NB: Look at circuit diagrams here on GitHub

Running Led and Button

Pins:

  • LED Anode to GPIO17
  • Button1 to GPIO4
  • Ground (LED Cathode and Button2) (to the one in between. <br>ie Pins 11 7 and 9 resectively.
  • Reminder that the LED requires a current limiting resistor.

SW driven LED

As above

DHT22

See circuit diagram under Circuits.
Active pin is is GPIO26. I'm using a 10K pullup to that.
Some conversions fail, which output as dots. Doesn't work on IOT-Core.

Motor

See circuit diagram in Circuits folder, left part. <br>Pins (L293D pins in brackets):

  • Enable GPIO 22 (E1) (L293D Enble 1)
  • Reverse GPIO 27 (I1)
  • Forward GPIO 17 (I2)

Relay

See circuit diagram in Circuits folder, right part. <br>Pins (L293D pins in brackets):

  • On/Off GPIO 19 (E2) (L233D Enable 2)
  • Lo (I4)
  • Hi (I3)
  • I4 and I3 only need to be in opposite state
  • Probably want Motor disabled if is low voltage and relay is 12V coil voltage.

BME280

  • See circuit diagram rpi-bmp280_i2c.png for 4 pin connections.
  • If unit is more than 4 pins see BME280Sampler.Get() for extra pins.
  • Also see there wrt enabling I2C on RPi and for checking.

Azure IOT Hub

  • Can periodicly send sensor readings to an Azure IoT Hub
  • Option 30. DHT22 1-Wire (2Do)
  • Option 31. BME280
  • Both connected as per DHT22 and BME280 above.
  • Need 2 additional parameters:
    • Period: Time in seconds beteween readings, eg 10
    • DeviceConnectionString
  • Nb: Need to provide 4 parameters in these cases:
    • [30|31] gpioString period deviceconnectionstring
      • gpioString and period can both be a dot
      • In these cases the defaults are used:
        • gpioString default is "17,4,26,22,27,17,19"
          • Hint: You can replace individual gpios in the string with a dot and the default is used for that.
        • period: default is 10

More on My Blog

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.3 483 3/30/2022
1.3.2 374 3/29/2022
1.3.1 375 3/27/2022
1.3.0 369 3/26/2022
1.2.2 376 3/20/2022
1.2.1 371 3/20/2022
1.2.0 400 3/20/2022
1.1.2 398 3/20/2022
1.1.1 396 3/19/2022
1.1.0 382 3/19/2022
1.0.9 385 3/19/2022
1.0.8 394 3/11/2022
1.0.7 398 3/11/2022
1.0.6 396 3/9/2022
1.0.5 371 3/9/2022
1.0.4 377 3/1/2022
1.0.3 371 2/28/2022
1.0.1 382 2/28/2022

Fixing some MORE async issues.