question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple controllers, same pin inconsistency

See original GitHub issue

This might not actually be a bug but it’s something that we might need to discuss.

I was testing the framework, and created the following scenario:

  • Have an app that deals with turning a light on and off
  • Have another app that checks if a led is on, and if so do something else.

Essentially, we will have 2 controllers that will use the same pin.

From my understanding, 1 controller should only work with a set of pins, and it should not “play around” with pins used by another controller.

Steps to reproduce

using System;
using System.Device.Gpio;
using System.Threading;

namespace temp
{
    class Program
    {
        static void Main(string[] args)
        {
			GpioController controller1 = new GpioController();
			controller1.OpenPin(10, PinMode.Output);
			controller1.Write(10, PinValue.High);
			Thread.Sleep(5000);
			GpioController controller2 = new GpioController();
			controller2.OpenPin(10, PinMode.Input);
			controller2.Read(10);

			controller1.ClosePin(10);
			controller2.ClosePin(10);
        }
    }
}

Expected behavior I would expect to be able to read the value and the pin keep the same state (High - meaning the led is on).

Actual behavior The LED turns on, but when I read the value from it, it reports as LOW and the LED turns off, although it was expected to be HIGH.

If I try to simplify (this might actually be another issue, let me know if I should create another) and do:

  • First app turns ON the LED and exits (closes the pin and ends)
  • As soon as I close the Pin, the LED turns off because the state is set to LOW. (why does this even happen?)
  • Second app will always read low, since the first app set it to LOW when closed the pin

Versions used

Add following information:

  • dotnet --info on the machine being used to build
.NET Core SDK (reflecting any global.json):
 Version:   2.2.402
 Commit:    c7f2f96116

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.402\

Host (useful for support):
  Version: 2.2.7
  Commit:  b1e29ae826

.NET Core SDKs installed:
  2.2.402 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]```

- `dotnet --info` on the machine where app is being run (not applicable for self-contained apps)

It was not possible to find any installed .NET Core SDKs Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from: https://aka.ms/dotnet-download

Host (useful for support): Version: 3.0.0 Commit: 7d57652f33

.NET Core SDKs installed: No SDKs were found.

.NET Core runtimes installed: Microsoft.AspNetCore.App 3.0.0 [/home/pi/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.0.0 [/home/pi/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download```

  • Version of System.Device.Gpio package: Version=“1.0.0”

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
microhobbycommented, Feb 15, 2020

@joperezr ok, make sense. I fully agree to communicate and encourage the use of libgpiod. In the future I see no way out, these interfaces will be disabled in the distros. Fedora has started shipping without /sys/class/gpio for example: https://fedoraproject.org/wiki/Architectures/ARM/gpio

And I think other distros will follow this move soon.

1reaction
joperezrcommented, Feb 10, 2020

TBH I don’t think it isn’t a very good idea to package a third party library and distribute it through our NuGet packages since that would mean that everytime that libgpiod has a fix, update or new feature we would have to react by shipping a new package again. We have cases in dotnet core where we depend on native libraries that are not preinstalled on all distros (like icu library for all of our globalization and localization libraries) which we don’t package with our product, but instead just call out that if consumers want to use that feature they will have to preinstall some libs. I’m totally fine with communicating that installing libgpiod is the recommended way, or even condition some future new features only if you have libgpiod if not possible to do them with sysfs, but having the ability to fallback in case you really don’t want to install the native library is still valuable I believe.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BUG: Multi use pins / shared pins don't work if aliased
There's an inconsistency in how board_pins aliases work compared to regular pin names. In short, this works:
Read more >
Crown 202c inconsistent pin connection : r/fightsticks
My crown 202's seem to be very inconsistent. They randomly stop working and after talking with another redditter who had the same issue...
Read more >
GPO Drive mappings over two-way trust is inconsistent
I have an old AD domain (with non-routable domain name) and am moving all users/resources to a new "routable" AD domain on a...
Read more >
Inconsistent operation of PIC microcontroller
There are two programming modes for PICs high voltage "HVP" and low voltage "LVP". With HVP, you enter programming by applying a voltage ......
Read more >
Wiring rework fixing inconsistency and unintuitiveness #5001
Let's start with 3: Of course it's logical that multiple components controlling the same input pin leads to unexpected behaviour, but it's possible...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found