Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # From the book, "The BeagleBone Black Primer, (McLaughlin 2016)."
- # Trying currently to set up Step_PIN2 and Dir_PIN2 for usage on one Stepper...
- import Adafruit_BBIO.GPIO as GPIO
- from time import sleep
- import ctypes
- libc = ctypes.CDLL('libc.so.6')
- Step_PIN1 = 'P9_16'
- Dir_PIN1 = 'P8_18'
- Step_PIN2 = 'P9_14'
- Dir_PIN2 = 'P8_16'
- MicroSteps = 8
- def move(steps, speed):
- if steps > 0:
- GPIO.output(Dir_PIN1, GPIO.HIGH)
- else:
- GPIO.output(Dir_PIN1, GPIO.LOW)
- steps = abs(steps)
- delay = ((float(speed) / 2) / MicroSteps) * 1000
- steps_remaining = steps
- while steps_remaining > 0:
- GPIO.output(Step_PIN1, GPIO.HIGH)
- libc.usleep(int(delay))
- GPIO.output(Step_PIN1, GPIO.LOW)
- libc.usleep(int(delay))
- steps_remaining = steps_remaining - 1
- def move_degrees(degrees, speed, degrees_per_step=1.8, usteps_per_step=8):
- steps = degrees / (degrees_per_step / usteps_per_step)
- move(steps, speed)
- if __name__=='__main__':
- GPIO.setup(Step_PIN1, GPIO.OUT)
- GPIO.output(Step_PIN1, GPIO.LOW)
- GPIO.setup(Dir_PIN1, GPIO.OUT)
- GPIO.output(Dir_PIN1, GPIO.HIGH)
- try:
- move_degrees(90, 100)
- sleep(2)
- move_degrees(-90, 100)
- sleep(2)
- move_degrees(360, 10)
- sleep(2)
- move_degrees(-360, 2.64)
- sleep(2)
- move_degrees(360 * 2, 3)
- sleep(2)
- except KeyboardInterrupt:
- pass
- finally:
- GPIO.output(Step_PIN1, GPIO.LOW)
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement