Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import time
- # Define GPIO pins
- IN1 = 17
- IN2 = 18
- IN3 = 22
- IN4 = 23
- # Set GPIO mode
- GPIO.setmode(GPIO.BCM)
- # Set up GPIO pins
- GPIO.setup(IN1, GPIO.OUT)
- GPIO.setup(IN2, GPIO.OUT)
- GPIO.setup(IN3, GPIO.OUT)
- GPIO.setup(IN4, GPIO.OUT)
- import RPi.GPIO as GPIO
- import time
- # Define GPIO pins
- IN1 = 17
- IN2 = 18
- IN3 = 22
- IN4 = 23
- # Set GPIO mode
- GPIO.setmode(GPIO.BCM)
- # Set up GPIO pins
- GPIO.setup(IN1, GPIO.OUT)
- GPIO.setup(IN2, GPIO.OUT)
- GPIO.setup(IN3, GPIO.OUT)
- GPIO.setup(IN4, GPIO.OUT)
- def set_step(w1, w2, w3, w4):
- GPIO.output(IN1, w1)
- GPIO.output(IN2, w2)
- GPIO.output(IN3, w3)
- GPIO.output(IN4, w4)
- # Example sequence for full step
- seq = [
- [1, 0, 1, 0],
- [0, 1, 0, 1]\
- #,
- #[0, 0, 1, 1],
- #[1, 0, 0, 1]
- ]
- import RPi.GPIO as GPIO
- import time
- # Define GPIO pins
- IN1 = 17
- IN2 = 18
- IN3 = 22
- IN4 = 23
- # Set GPIO mode
- GPIO.setmode(GPIO.BCM)
- # Set up GPIO pins
- GPIO.setup(IN1, GPIO.OUT)
- GPIO.setup(IN2, GPIO.OUT)
- GPIO.setup(IN3, GPIO.OUT)
- GPIO.setup(IN4, GPIO.OUT)
- import RPi.GPIO as GPIO
- import time
- # Define GPIO pins
- IN1 = 17
- IN2 = 18
- IN3 = 22
- IN4 = 23
- # Set GPIO mode
- GPIO.setmode(GPIO.BCM)
- # Set up GPIO pins
- GPIO.setup(IN1, GPIO.OUT)
- GPIO.setup(IN2, GPIO.OUT)
- GPIO.setup(IN3, GPIO.OUT)
- GPIO.setup(IN4, GPIO.OUT)
- def set_step(w1, w2, w3, w4):
- GPIO.output(IN1, w1)
- GPIO.output(IN2, w2)
- GPIO.output(IN3, w3)
- GPIO.output(IN4, w4)
- # Example sequence for full step
- seq = [
- [1, 0, 1, 0],
- [0, 1, 1, 0],
- [0, 1, 0, 1],
- [1, 0, 0, 1]
- ]
- # Rotate stepper motor clockwise
- def clockwise(delay, steps):
- for _ in range(steps):
- for halfstep in range(4):
- set_step(seq[halfstep][0], seq[halfstep][1], seq[halfstep][2], seq[halfstep][3])
- time.sleep(delay)
- # Rotate stepper motor counterclockwise
- def counterclockwise(delay, steps):
- for _ in range(steps):
- for halfstep in range(4):
- set_step(seq[3 - halfstep][0], seq[3 - halfstep][1], seq[3 - halfstep][2], seq[3 - halfstep][3])
- time.sleep(delay)
- # Example usage
- try:
- while True:
- print('clockwise')
- clockwise(0.5, 10) # Rotate clockwise 200 steps with 0.01s delay between steps
- time.sleep(0.5)
- print('counter clockwise')
- counterclockwise(0.5, 10) # Rotate counterclockwise 200 steps with 0.01s delay between steps
- time.sleep(0.5)
- time.sleep(5)
- except KeyboardInterrupt:
- print("Program stopped by user")
- finally:
- GPIO.cleanup() # Clean up GPIO on exit
- # Example usage
- try:
- while True:
- print('clockwise')
- clockwise(0.1, 100) # Rotate clockwise 200 steps with 0.01s delay between steps
- time.sleep(0.5)
- # print('counter clockwise')
- # counterclockwise(0.1, 100) # Rotate counterclockwise 200 steps with 0.01s delay between steps
- # time.sleep(0.5)
- # time.sleep(5)
- except KeyboardInterrupt:
- print("Program stopped by user")
- finally:
- GPIO.cleanup() # Clean up GPIO on exit
Advertisement
Add Comment
Please, Sign In to add comment