Advertisement
silver2row

figuring out what does what in GPIO/PWM

Mar 10th, 2023
1,110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 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. CHIP1 = 'gpiochip1'
  15. LINE_OFFSET1 = [18]
  16.  
  17. chip = gpiod.Chip(CHIP)
  18. chip1 = gpiod.Chip(CHIP1)
  19.  
  20. lines = chip.get_lines(LINE_OFFSET)
  21. lines.request(consumer=' ', type=gpiod.LINE_REQ_DIR_OUT)
  22.  
  23. lines1 = chip.get_lines(LINE_OFFSET1)
  24. lines1.request(consumer=' ', type=gpiod.LINE_REQ_DIR_IN)
  25.  
  26. lines.set_values([0])
  27. #lines1.set_values([0])
  28.  
  29. try:
  30.     port = int(input("Please type 0 or 1 : "))
  31.     if port == 0:
  32.         lines.set_values([0])
  33.         pwm1b = Pwm('/dev/bone/pwm/1/b/', frequency=2000)
  34.         pwm1b.value = 0.5
  35.         sleep(1)
  36.         lines.set_values([1])
  37.         sleep(5)
  38.     elif port == 1:
  39.         lines1.set_values([0])
  40.         pwm1b = Pwm('/dev/bone/pwm/1/b/', frequency=0)
  41.         pwm1b.value = 0.0
  42.         sleep(1)
  43.         lines1.set_values([1])
  44.         sleep(1)
  45.  
  46. except KeyboardInterrupt:
  47.     lines.set_values([0])
  48.     lines1.set_values([0])
  49.     pwm1b = Pwm('/dev/bone/pwm/1/b', frequency=0)
  50.     pwm1b.value = 0.0
  51.     print("Kosher Salt!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement