Skip to content

djaus2/DNETCoreGPIO

Repository files navigation

                                                                                                                                                           # DNETCoreGPIO

TRIGGERcmd Now implemendted for control of RPi using this app. See https://github.com/djaus2/TRIGGERcmdRPi

Currently .Net 5.0 and 2.1.0 for GPIO and Device Bindings.

Functionality is now a library which is called by a simple Console App. Can also get from Nuget.

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.

Another: Can set,clear,toggle LED as single commands with options 16,17 and 18. Nb Uses a temp file to indicate state.


A .NET Core app to run on the RPi. Works with both Raspian and Win10 IoT-Core unchanged. Exemplifies System.Devices.GPIO and Iot.Device.Bindings Nuget packages. Provided as Visual Studio 2022 project.

This is based upon the GitHUb Repository: dotnet/iot
Whereas the samples therein (from which this is taken, and extended) use library sources in that repository, this uses the associated Nuget packages.

Code includes:(i.e. Run the app with one of the following as the first parameters)

  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 ditt0

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

To run

  • If publishing from desktop to RPI, from within the deployed folder: ./DNETCoreGPIO n on Raspian or .\DNETCoreGPIO n in a PowerShell windows on IoT-Core, where n is 1,2 ... 6 as above.
  • Assuming the .Net Framework is installed (Net 6 for latest) on the RPi etc:
    • If cloned repository to RPI, dotnet build in the root of the repository clone then dotnet run n there where n is 1..6 as above.
      • Or DNETCoreGPIO n if built folder, eg ~/GPIO/DNETCoreGPIO/bin/net6.0 is in the PATH
    • In this latest iteration I installed VS Code on the RPi.

Run

Running Led and Button

Pins:

  • LED Anode to GPIO17
  • Button1 to GPIO4
  • Ground (LED Cathode and Button2) (to the one in between.
    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.
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.
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.

On IoT-Core DO NOT RUN IN POWERSHELL. Can't get user input for Console app in Remote PowerShell.
Run an SSH session.
Or directlly on the device.
I also attached a LED to each output.

Publishing

You need to Publish the app from Visual Studio for linux-arm or win-arm. You can publish to a share of the Pi, or build to a folder on the desktop and then copy or send it across.

  • You can Publish as Framework Independent. See Raspian publish profile (It publishes to a share).Correction .. currently publishes to desktop folder
  • Or Build as Framework dependent. The IoT-Core publish profile publishes to a folder under \bin. You copy iot from there.

NB: You could though build and deploy from VS Code.

More on My Blog

Releases

No releases published

Packages

No packages published

Languages