Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Have a 'Type' for GPIO Object that can be input or output #28

Open
jnury opened this issue Apr 15, 2018 · 9 comments
Open

Have a 'Type' for GPIO Object that can be input or output #28

jnury opened this issue Apr 15, 2018 · 9 comments

Comments

@jnury
Copy link
Contributor

jnury commented Apr 15, 2018

Hi,

Using Get-GpioPin on a pin will force its level to 'low'.

To reproduce (even if the pin is not connected to anything):

Set-GpioPin -Id 0 -Value High

The pin is high.

Get-GpioPin -Id 0

Returns:

Id Value PinInfo
-- ----- -------
 0   Low Unosquare.RaspberryIO.Gpio.GpioPin

And the pin is low :-/

@TylerLeonhardt
Copy link
Member

This is going to sound crazy... but you cannot set a pin and then get it's value. GPIO doesn't really work this way. A pin is either a setter or a getter.

Once you set a pin, it's marked as an "input" pin with the value of "high" (or "low").

Once you get a pin, it's marked as an "output" pin with no guarantee that it will hold the value of the previous set operation.

@anmenaga can explain this further.

@jnury
Copy link
Contributor Author

jnury commented Apr 15, 2018

Hum, my bad, Arduino (bad) habits :-D

Maybe we should have an object 'GPIOPin' with a 'type' = input|output and a Value that we can get/set if the type is Output or simply get if the type is Input.

BTW: thank you for you fast and detailed answer ;-)

@TylerLeonhardt
Copy link
Member

That's a great idea :) lets change the name of this issue to support that.

@TylerLeonhardt TylerLeonhardt changed the title Get-GpioPin force the pin to 'low' level Have a 'Type' for GPIO Object that can be input or output Apr 15, 2018
@jnury
Copy link
Contributor Author

jnury commented Apr 17, 2018

After digging a bit in docs (I'm not quite familiar with Arduino GPIO), it seems that is really easy to read status of an output pin.

Example with GPIO 2:

echo "27" > /sys/class/gpio/export
cat /sys/class/gpio/gpio7/value

I'll have a look if it's possible to use existing WirePi/RaspberryIO method or PR something to these projects to support that ;-)

@TylerLeonhardt
Copy link
Member

That would be awesome! Pull requests always welcome 😃

@jaswalters
Copy link

jaswalters commented Dec 11, 2018

@TylerLeonhardt

This is going to sound crazy... but you cannot set a pin and then get it's value. GPIO doesn't really
work this way. A pin is either a setter or a getter

Once you set a pin, it's marked as an "input" pin with the value of "high" (or "low").

Once you get a pin, it's marked as an "output" pin with no guarantee that it will hold the value of the previous set operation.

So I'm new to GPIO but not to PowerShell. My history on Po$h is that a Get- would get the value of whatever object that value is holding or set to.

When it comes to GPIO how is Get-GPIOPin to be used?

How would you get the value of say Pin 2 to see if it's currently "High" or "Low"?

@TylerLeonhardt
Copy link
Member

You would just use Get-GpioPin but keep in mind that GPIO does not let you Set and then Get. This is a fundamental concept of GPIO.

You would only use Get-GpioPin to get High or Low FROM hardware that sets the value - like a physical button or a simple IR receiver.

You would only use Set-GpioPin to set High or Low TO hardware that uses the value - like an LED or a simple IR blaster.

@TylerLeonhardt
Copy link
Member

It took me a while to understand this 😆

@jaswalters
Copy link

jaswalters commented Dec 17, 2018

@jnury

After digging a bit in docs (I'm not quite familiar with Arduino GPIO), it seems that is really easy to read status of an output pin.

Example with GPIO 2:

echo "27" > /sys/class/gpio/export
cat /sys/class/gpio/gpio7/value

I'll have a look if it's possible to use existing WirePi/RaspberryIO method or PR something to these projects to support that ;-)

RaspberryIO can read a pin value like this.
Pi.Gpio.Pin02.PinMode = GpioPinDriveMode.Input;
// The below lines are roughly equivalent
var isOn = Pi.Gpio.Pin02.Read(); // Reads as a boolean
var pinValue = Pi.Gpio.Pin02.ReadValue(); // Reads as a GpioPinValue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants