from machine import Pin, PWM
import time
# Define the pins connected to the A4988
step_pin = Pin(14, Pin.OUT)
dir_pin = Pin(12, Pin.OUT)
ms1_pin = Pin(27, Pin.OUT)
ms2_pin = Pin(26, Pin.OUT)
ms3_pin = Pin(25, Pin.OUT)
# Microstepping setup
# Microstepping options: Full step (000), Half step (100), Quarter step (010), Eighth step (011), Sixteenth step (111)
microstep_mode = (1, 1, 1) # Sixteenth step
ms1_pin.value(microstep_mode[0])
ms2_pin.value(microstep_mode[1])
ms3_pin.value(microstep_mode[2])
# Configure direction (0 or 1)
dir_pin.value(1)
# Function to perform steps
def step(steps, delay):
for _ in range(steps):
step_pin.value(1)
time.sleep(delay)
step_pin.value(0)
time.sleep(delay)
# Example usage
num_steps = 200 * 16 # Number of steps (200 steps per revolution * 16 microsteps)
delay_between_steps = 0.001 # Delay in seconds
print("Starting microstepping...")
step(num_steps, delay_between_steps)
print("Microstepping completed.")