Advertisement
silver2row

yearning and earning...Python

Mar 22nd, 2023 (edited)
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. # Use for PWM on /dev/bone/pwm/
  2.  
  3. from pathlib import Path
  4. from sysfs_pwm import Pwm  # see https://pastebin.com/R70P1wAn
  5. from time import sleep
  6.  
  7. pwm1b = Pwm('/dev/bone/pwm/1/b/', frequency=50, value=0)
  8.  
  9. GPIO  = Path('/sys/class/gpio/gpio48/direction')
  10. GPIO.write_text('out')
  11. GPIO  = Path('/sys/class/gpio/gpio48/value')
  12. GPIO.write_text('0')
  13.  
  14. GPIO1 = Path('/sys/class/gpio/gpio26/direction')
  15. GPIO1.write_text('out')
  16. GPIO1 = Path('/sys/class/gpio/gpio26/value')
  17. GPIO1.write_text('0')
  18.  
  19. # https://pastebin.com/R70P1wAn
  20.  
  21. # initialize and enable pwm, automatically disable when scope is left
  22. #with Pwm('/dev/bone/pwm/1/b', frequency=20000, value=0) as pwm:
  23. #    while True:
  24. #        pwm.value = float(input("Enter PWM value (between 0.0 and 1.0): "))
  25.  
  26. try:
  27.     while True:
  28.         port = int(input("Please type 0 or 1 : "))
  29.         if port == 0:
  30.             GPIO.write_text('1')
  31.             pwm1b.frequency=50
  32.             pwm1b.value=0.2
  33.             sleep(1)
  34.         elif port == 1:
  35.             GPIO.write_text('1')
  36.             pwm1b.frequency=50
  37.             pwm1b.value=0.3
  38.             sleep(1)
  39.  
  40. except KeyboardInterrupt:
  41.     GPIO.write_text("0")
  42.     GPIO1.write_text("0")
  43.     pwm1b.enabled = False
  44.     print("Kosher Salt!")
  45.  
  46. and...The file in question, i.e. (TB6600_PWM.py)
  47.  
  48. debian@BeagleBone:~/Ball_Screw/Third$ ./TB6600_PWM.py
  49. Please type 0 or 1 : 1
  50. Please type 0 or 1 : 0
  51. Traceback (most recent call last):
  52.   File "/home/debian/Ball_Screw/Third/./TB6600_PWM.py", line 33, in <module>
  53.     pwm1b.frequency=50
  54.   File "/home/debian/Ball_Screw/Third/sysfs_pwm.py", line 144, in frequency
  55.     raise RuntimeError("Cannot set frequency when PWM value is non-zero (i.e. duty_cycle is non-zero)")
  56. RuntimeError: Cannot set frequency when PWM value is non-zero (i.e. duty_cycle is non-zero)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement