Is it possible to open a pin with PinMode.Input and PinMode.Output?
See original GitHub issueI’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:
- Created 10 months ago
- Comments:23 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
thanks for help! I appreciate this
@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.