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

Fix PWM bug when pin already exported #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

salamantos
Copy link

Problem

If pin was already in use, you will get error:

Traceback (most recent call last):
  File "/home/orangepi/feeder/start.py", line 11, in <module>
    PWM_Class.start_pwm()
  File "/usr/local/lib/python3.10/dist-packages/OPi/GPIO.py", line 749, in start_pwm
    return sysfs.PWM_Duty_Cycle_Percent(self.chip, self.pin, self.duty_cycle_percent)  # duty cycle controls the on-off
  File "/usr/local/lib/python3.10/dist-packages/OPi/sysfs.py", line 164, in PWM_Duty_Cycle_Percent
    with open(path, "w") as fp:  # pretty sure this
OSError: [Errno 22] Invalid argument

and PWM will not be enabled

Solution

This is due to try-except in PWM init method: if device already in use, it re-exports, but skips enabling and duty-cycle set

So I just moved latter logic after try-except block

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 this pull request may close these issues.

1 participant