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.

Is it possible to open a pin with PinMode.Input and PinMode.Output?

See original GitHub issue

I’m trying to write 1/0 to pin and listening all changes.

my code:

using System.Device.Gpio;
using System.Device.Gpio.Drivers;

var _gpioController = new GpioController(
    numberingScheme: PinNumberingScheme.Logical,
    driver: new SysFsDriver());

var relayPin = 128 + 21;
var highTime = 1000;
var lowTime = 200;

System.Console.WriteLine("start openning");

_gpioController.OpenPin(
    relayPin,
    PinMode.Input );

System.Console.WriteLine("opened");

System.Console.WriteLine("registering handlers");

_gpioController.RegisterCallbackForPinValueChangedEvent(
    pinNumber: relayPin,
    eventTypes: PinEventTypes.Rising,
    callback: (_, args) =>
    {
        Console.WriteLine($"{args.PinNumber} is rising");
    });

System.Console.WriteLine("try to set new pin mode");

_gpioController.SetPinMode(
    pinNumber: relayPin,
    mode: PinMode.Output);

System.Console.WriteLine("start relay test");

while (true)
{
    _gpioController.Write(relayPin, PinValue.High);
    Thread.Sleep(highTime);

    _gpioController.Write(relayPin, PinValue.Low);
    Thread.Sleep(lowTime);
}

Unfortunately only _gpioController.Write.. works. Is it possible to listen and to write?

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
INTERNALINTERFERENCEcommented, Nov 18, 2022

thanks for help! I appreciate this

1reaction
joperezrcommented, Nov 17, 2022

@INTERNALINTERFERENCE the main issue with your code is that, as @raffaeler explained, you can’t really have a pin operating both as input and output. The easiest way to do a hello world program that tests for detecting events uses two pins instead of just one. You connect them via a wire physically, and set one as input (and configure the callback exactly like you do in your code) and then you set the other pin as output. Then you write to the output pin 0s and 1s, and your callback should get fired every time that you write a 1 to the output pin after writing a 0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pinMode() - Arduino Reference
Configures the specified pin to behave either as an input or an output. See the Digital Pins page for details on the functionality...
Read more >
Is it possible to change pin operation from output to input ...
Yes. Just call pinMode([pin], [mode]) whenever you want to change from input to output or output to input. How to decide when to...
Read more >
pinMode() - Input/Output | Reference
pinMode. pinMode() configures the specified pin to behave either as an input (with or without an internal weak pull-up or pull-down resistor), or...
Read more >
How can I digitalRead a pin that is in pinMode OUTPUT?
I have come to understand that changing the pinMode will stop it from being HIGH . So setting a pin to HIGH in...
Read more >
Arduino INPUT_PULLUP Explained (pinMode)
This is quite simple: you plug one leg of the push button to the ground (GND), and another one – on the other...
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