The DNETCoreGPIO repository has been further refined and extended with increased focus upon creating the app as a simple Console app that uses the package directly.

DNETCoreGPIO is a ,NET project was developed to demonstrate hardware interaction on a RPi using System.Devices.GPIO and Iot.Device.Bindings APIs. The original repository was a single console app suing .NET Core. The repository has been modified so as to refactor the functionality into a .NET library project and a simple console app that uses the library. The library was then published on Nuget and a simple Console app was added to the repository that uses the Nuget package rather than the library.

The app takes a numerical parameter that specifies what function it is to perform. The original app demonstrated GPIO functionality using a LED and switch as well as a H-Bridge Motor control. It also was able to read environment values through -Wire DHT22 and BME280 sensors. This app ran continuously taking user input. Control of a relay was also added.

The app was then modified so as to run once, performing just a single action. It can for example, enable the motor, disable it, set in forwards mode or reverse. It can also read the temperature once and write that to a temp file. Th purpose of these multiple single issue modes is as part of the Google Home Bridge integration where each can be invoked by a single “Hey Google, “ voice command. I can say to my Google Nest, “Hey Google, start temp on Pi”. Eventually the Nest will enunciate the result as determined by the BME280 sensor on the RPi.

Recent functionality added to the app/library is the ability to set,clear or toggle the state of a specific GPIO pin on eth RPi. Also an optional second parameter, as a CSV list string, can dynamically set which GPIO pins to use on the RPi for the LED, switch, motor and relay.

The Nuget package has been updated many times including several of late to correct the GPIO toggle functionality. Whilst I should have debugged this locally, I did this in a lazy way … sorry to those who tracked this. I made the code changes and published and only checked the functionality with the published package. Whilst the GPIO set and clear worked OK, the toggle would only set the GPIO pin. Given that the set,clear, toggle app modes run and exit, there is no in-app memory of the state of the pin for toggling. I did try reading the state of the pin as input first but that did not work:

    controller.OpenPin(pinRLED, System.Device.Gpio.PinMode.Input);
    LEDState = (PinValue.High == controller.Read(pinRLED));
    controller.ClosePin(pinRLED);
    controller.OpenPin(pinRLED, System.Device.Gpio.PinMode.Output);
    ...

What did work was to write a temp file if the pin was set or remove it (if it exists) if the pin is cleared. In toggle mode it then checks for the file’s existence. That works as in version 1.2.1 of the Nuget package.

It is also noted that if the Console app hosting the Nuget package is .NET 6 then the Program.cs file only needs to be one line:

DotNetCoreCoreGPIO.Program.Main(args)

So to implement the Console app locally:

1.Create a .NET Console app: Run dotnet new console

2.Add the library as a Nuget package Run dotnet add package DNETCoreGPIO

3.Replace the Console.WriteLine("Hello, World!"); line with:

DotNetCoreCoreGPIO.Program.Main(args)

Build and run the app with the required parameter. See the links above for the parameters to use and for wiring. So it is quite easy to get this functionality on a RPi!


PS: I am tempted to rename the package etc, DNETGPIO as the Core part of the terminology is legacy.

Coming: “Hey Google, ..” with azure IoT Hub!


 TopicSubtopic
<  Prev:   Nuget Packages 101
   
 This Category Links 
Category:IoT Index:IoT
  Next: > Google Home Windows Bridge
<  Prev:   Google Home Windows Bridge