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

The initial arguments defined in setup function does not take effect #49

Open
vava24680 opened this issue Aug 11, 2020 · 6 comments
Open
Labels
Quality Engineering Verification of correctness with respect to requriements Software Engineering/Bug Something isn't working

Comments

@vava24680
Copy link

Hi, I had the problem that the initial argument defined in setup function does not take effect. Below is what I did.

from RPi import GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.OUT, initial=GPIO.LOW) # It does not set the initial value to low.

I ran this code under the newest version of this package and the platform is Raspberry Pi 4B+.

No matter I passed low or high, it always set the same initial value. Can somebody help me or point out what's going on?

Thank you

@theyoyojo
Copy link
Contributor

Hi,

Thanks for raising this issue, I'll look into it and see what I can find.

@vava24680
Copy link
Author

I think I may know what's the problem.
The value of GPIO.LOW is 2, so when it will be treated as the active high...

@theyoyojo
Copy link
Contributor

I was able to reproduce this issue. Definitely worth fixing.

I extended your code slightly to create this reproducer:

#!/bin/python3

from RPi import GPIO
from RPi import GPIO_DEVEL

pin=22

GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT, initial=GPIO.LOW) # It does not set the initial value to low.

input()

GPIO_DEVEL.Reset()

GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.OUT, initial=GPIO.HIGH) # Same behavior as initial=GPIO.LOW

input()

Would you like to submit a fix yourself? If not, I will patch the code.

@theyoyojo theyoyojo added Software Engineering/Bug Something isn't working Quality Engineering Verification of correctness with respect to requriements labels Aug 14, 2020
@vava24680
Copy link
Author

I think this is a bug from the python binding of the libgpiod. This link is how the GPIO.LOW is defined in the binding. As far as I know how the enum works in the C, the value of gpiod_ACTIVE_LOW will be 2.

I think I can submit a fix for this strange behavior by hardcoding the value of GPIO.LOW as 0 in the core.py. This is a temporary solution, but I think it's ok for the current using. Anyway, I will try to understand whether my guess is correct and see if I can submit a patch to the libgpiod.

@theyoyojo
Copy link
Contributor

@vava24680 hey, are you still working on this?

@vava24680
Copy link
Author

Sorry for the delay, I think I may patch this bug on this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Quality Engineering Verification of correctness with respect to requriements Software Engineering/Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants