Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't read input until after the output has been configured once when using circuits_gpio #3

Closed
pojiro opened this issue Mar 5, 2022 · 4 comments
Assignees

Comments

@pojiro
Copy link
Contributor

pojiro commented Mar 5, 2022

In below code, GPIO pin 26 is D18 of Grove Base Hat for Raspberry Pi.

iex(1)>  {:ok, gpio} = Circuits.GPIO.open(26, :input)  
{:ok, #Reference<0.1962860034.377356295.248080>}
iex(2)> Circuits.GPIO.read(gpio)
0 # button is not pushed
iex(3)> Circuits.GPIO.read(gpio)
0 # button is pushed, but can't read its value
iex(4)>  {:ok, gpio} = Circuits.GPIO.open(26, :output)      # once configure with output
{:ok, #Reference<0.1962860034.377356295.248081>}
iex(5)>  {:ok, gpio} = Circuits.GPIO.open(26, :input)       # make it back to input
{:ok, #Reference<0.1962860034.377356295.248082>}
iex(6)> Circuits.GPIO.read(gpio)
0 # button is not pushed
iex(7)> Circuits.GPIO.read(gpio)
1 # button is pushed, now can read its value

This doesn't happen with debian which boots with same kernel and same dtb.

debian@arm:~$ gpioget gpiochip1 10
0
debian@arm:~$ gpioget gpiochip1 10
1

So, this might be a contribution chance to circuits_gpio.

@pojiro pojiro added the help wanted Extra attention is needed label Mar 5, 2022
@pojiro pojiro self-assigned this Mar 5, 2022
@pojiro
Copy link
Contributor Author

pojiro commented Mar 27, 2022

I confirmed below, also works

iex(3)> cmd "echo 26 > /sys/class/gpio/export"
0
iex(4)> cmd "echo in > /sys/class/gpio/gpio26/direction"
0
iex(5)> cmd "cat /sys/class/gpio/gpio26/value"
0
0
iex(6)> cmd "cat /sys/class/gpio/gpio26/value"
1
0

@pojiro
Copy link
Contributor Author

pojiro commented Jul 24, 2022

Once a version containing elixir-circuits/circuits_gpio#119 is released, this issue is fixed.

@pojiro pojiro removed the help wanted Extra attention is needed label Jul 24, 2022
@pojiro
Copy link
Contributor Author

pojiro commented Aug 2, 2022

https://github.com/elixir-circuits/circuits_gpio/releases/tag/v1.0.1, includes above fix, is released.
Now we can close this, yey!

@pojiro pojiro closed this as completed Aug 2, 2022
@takasehideki
Copy link
Member

what a fantastic contribution!!

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

Successfully merging a pull request may close this issue.

2 participants