-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstepperAI.py.save
36 lines (29 loc) · 925 Bytes
/
stepperAI.py.save
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import RPi.GPIO as GPIO
import time
# Define GPIO pins
DIR = 20
STEP = 21
# Set up GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(DIR, GPIO.OUT)
GPIO.setup(STEP, GPIO.OUT)
GPIO.output(DIR, GPIO.HIGH)
# Define some parameters
delay = 0.001 # Adjust this value to change speed
steps_per_revolution = 200 # Number of steps per full revolution
# Function to move the stepper motor
def move_stepper(steps, direction):
for _ in range(steps):
GPIO.output(STEP, GPIO.HIGH)
time.sleep(delay)
GPIO.output(STEP, GPIO.LOW)
time.sleepz# Example usage
if __name__ == "__main__":
try:
while True:
move_stepper(steps_per_revolution, GPIO.HIGH) # Move clockwise
time.sleep(1)
move_stepper(steps_per_revolution, GPIO.LOW) # Move counterclockwise
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup() # Clean up GPIO on Ctrl+C exit