-
Notifications
You must be signed in to change notification settings - Fork 98
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
[feature request] Add pwm support #40
Comments
I have no plans to add i myself, but PRs welcome |
No problem, im a noob on dev, but I'll take a look and try :) |
There is a simple SoftPWM (not so fast) implementation which can be used with OPi.GPIO by some line changes. (it is for pyA20 originally) https://github.com/evergreen-it-dev/orangepwm/blob/master/orangepwm.py |
There is a OSError: [Errno 19] No such device
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/root/OPi.GPIO/Demo/PWM_Demo.py", line 10, in <module>
p = GPIO.PWM(PWM_chip, PWM_pin, frequency_Hz, Duty_Cycle_Percent) # new PWM on channel=LED_gpio frequency=38KHz
File "/usr/local/lib/python3.9/dist-packages/OPi.GPIO-0.5.2-py3.9.egg/OPi/GPIO.py", line 743, in __init__
raise e
File "/usr/local/lib/python3.9/dist-packages/OPi.GPIO-0.5.2-py3.9.egg/OPi/GPIO.py", line 729, in __init__
sysfs.PWM_Export(chip, pin) # creates the pwm sysfs object
File "/usr/local/lib/python3.9/dist-packages/OPi.GPIO-0.5.2-py3.9.egg/OPi/sysfs.py", line 95, in PWM_Export
fp.write(str(pin))
OSError: [Errno 19] No such device In import orangepi.zero
import OPi.GPIO as GPIO
from time import sleep # this lets us have a time delay
PWM_chip = 0
PWM_pin = 7
frequency_Hz = 3800
Duty_Cycle_Percent = 100
channel = PWM_pin
# Simple mode, let's make it blink-kkk
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PWM_pin, GPIO.OUT)
GPIO.output(PWM_pin, GPIO.HIGH)
sleep(0.1)
GPIO.output(PWM_pin, GPIO.LOW)
sleep(0.1)
GPIO.output(PWM_pin, GPIO.HIGH)
sleep(0.1)
# Let's play with PWM now
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT, pull_up_down=GPIO.PUD_UP)
p = GPIO.PWM(PWM_chip, 0, frequency_Hz, Duty_Cycle_Percent) # new PWM on channel=LED_gpio frequency=38KHz
print("turn on pwm by pressing button")
input()
p.start_pwm()
print("dimm pwm by pressing button")
input()
p.duty_cycle(50)
print("change pwm frequency by pressing button")
input()
p.change_frequency(500)
print("stop pwm by reducing duty cycle to 0 by pressing button")
input()
p.stop_pwm()
print("change polarity by pressing button")
input()
p.pwm_polarity()
print("increase duty cycle but inverted so light will dim. press button to contunue")
input()
p.duty_cycle(75)
print("duty cycle reduced press button to contunue")
input()
p.duty_cycle(25)
print("stop pwm (it was inverted so it shoudl be full brightness), press button to contunue")
input()
p.stop_pwm()
print("remove object and deactivate pwm pin, press button to contunue")
input()
p.pwm_close()
del p # delete the class
GPIO.cleanup() Do you know what I did wrong? Thanks. |
I think you're changing the pwm chip not the pin. Try leaving the chip as 0 and see what happens, if it gives an error saying the device doesn't exist try change it to 1, you shouldn't go above 2. Note as well that the chip is mapped to a specific pin and that pin may not be whats listed as the pwm pin on the pinout diagrams for the board (its a pain I know). For example in the image below I pointed where the pwm pin is located on that board. Hope this helps! |
Hello,
Do you plan to add Pwm support the the library?
The text was updated successfully, but these errors were encountered: