from machine import Pin
import time
# Pins configuration
DIR_PIN = 16
STEP_PIN = 17
ENABLE_PIN = 18 # Adjust if you have an enable pin connected
# Setup pins
dir_pin = Pin(DIR_PIN, Pin.OUT)
step_pin = Pin(STEP_PIN, Pin.OUT)
enable_pin = Pin(ENABLE_PIN, Pin.OUT)
# Enable the driver (usually LOW means enabled)
enable_pin.value(0) # Enable the driver
def step(steps, direction, delay=0.002):
dir_pin.value(direction)
for i in range(steps):
step_pin.value(1)
time.sleep(delay)
step_pin.value(0)
time.sleep(delay)
while True:
print("Rotating forward")
step(200, 1)
time.sleep(1)
print("Rotating backward")
step(200, 0)
time.sleep(1)