Advertisement
silver2row

configure PWM/GPIO for Motor

Mar 10th, 2023
1,225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # Use for PWM on /dev/bone/pwm/
  4.  
  5. #from pathlib import Path
  6. from NewMotor_TB6600 import Pwm  # see https://pastebin.com/R70P1wAn
  7. from time import sleep
  8. import gpiod
  9. import os
  10.  
  11. CHIP = 'gpiochip1'
  12. LINE_OFFSET = [28]
  13.  
  14. chip = gpiod.Chip(CHIP)
  15.  
  16. lines = chip.get_lines(LINE_OFFSET)
  17. lines.request(consumer=' ', type=gpiod.LINE_REQ_DIR_OUT)
  18.  
  19. lines.set_values([0])
  20.  
  21. pwm1b = Pwm('/dev/bone/pwm/1/b/')
  22. pwm1a = Pwm('/dev/bone/pwm/1/a/')
  23.  
  24. try:
  25.     while True:
  26.         port = int(input("Please type 0 or 1 : "))
  27.         if port == 0:
  28.             lines.set_values([1])
  29.             pwm1b.duty_cycle = 1000
  30.             pwm1b.frequency = 2000
  31.             pwm1b.value = 0.5
  32.             pwm1b.enabled = True
  33.             sleep(2)
  34.         elif port == 1:
  35.             lines.set_values([1])
  36.             pwm1a.duty_cycle = 1000
  37.             pwm1a.frequency = 2000
  38.             pwm1a.value = 0.5
  39.             pwm1a.enabled = True
  40.             sleep(2)
  41. except KeyboardInterrupt:
  42.     pwm1b.enabled = False
  43.     pwm1a.enabled = False
  44.     print("Kosher Salt!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement