Hi All I am trying to build a rotating platform which will acomodate either a point and shoot style camera or a dslr for timelapse photography.
My tests are using a 24byj 48 stepper and the makerverse 2ch motor driver( PART NO ce08038) but will eventually be upgraded to a Nema 17 style stepper.
At the moment the code below is set to do 2000 steps in one direction and then 2000 in the other.
At the moment the motor will not move , even though I can hear it and feel it vibrate when the Pico and the seperate power supply are turned on.
Once I have this operating I will change the code to move only 10 steps (approx) and to pause between each 10 steps and flash a Led which will also become an output trigger pulse to a camera.
I am obviously missing something in this code as the motor is not turning .
The connections are correct because I can run other simpler code ( which Brenton supplied in one of the Core guides) without a problem.
PLEASE NOTE : The code compiles and gives me these 2 messages but nothing happens
print(“Rotating 2000 steps in one direction…”)
print(“Rotating 2000 steps in the other direction…”)
Any suggestions greatly appreciated
Nick
from machine import Pin, PWM
import time
from Makerverse_Motor_2ch import bipolarStepper
stepper = bipolarStepper(pwmPinA = 0, dirPinA = 1, pwmPinB = 2, dirPinB = 3, RPM = 100, stepsPerRotation = 2048)
# Define pins for your stepper motor driver
DIR_PINA = 1 # Example GPIO pin for direction
PWM_PINA = 0 # Example GPIO pin for step (PWM) STEP
DIR_PINB = 3 # Example GPIO pin for direction
PWM_PINB = 2 # Example GPIO pin for step (PWM) STEP
# Configure the direction pin
dir_pinA = Pin(DIR_PINA, Pin.OUT)
dir_pinB = Pin(DIR_PINB, Pin.OUT)
# Configure the PWM for the step pin
# Frequency determines the speed of stepping (higher freq = faster)
# Duty cycle controls the pulse width (e.g., 512 for 50% duty cycle)
pwm_PinA = PWM(Pin(PWM_PINA))
pwm_PinA.freq(1000) # Set a base frequency for stepping (e.g., 1kHz)
pwm_PinB = PWM(Pin(PWM_PINB))
pwm_PinB.freq(1000) # Set a base frequency for stepping (e.g., 1kHz)
def rotate_stepper(steps, direction, delay_ms=1):
"""
Rotates the stepper motor for a given number of steps in a specified direction.
Args:
steps (int): The number of steps to rotate.
direction (int): 0 for one direction, 1 for the other.
delay_ms (int): Delay between step pulses in milliseconds.
"""
dir_pinA.value(1) # Set the direction
time.sleep_ms(10) # Small delay after changing direction (driver specific)
dir_pinB.value(1) # Set the direction
time.sleep_ms(10) # Small delay after changing direction (driver specific)
dir_pinA.value(0) # Set the direction
time.sleep_ms(10) # Small delay after changing direction (driver specific)
dir_pinB.value(0) # Set the direction
time.sleep_ms(10) # Small delay after changing direction (driver specific)
for _ in range(steps):
pwm_PinA.duty_u16(32768) # Set duty cycle to 50% (half of 65535 for 16-bit)
time.sleep_ms(delay_ms)
pwm_PinB.duty_u16(32768) # Set duty cycle to 50% (half of 65535 for 16-bit)
time.sleep_ms(delay_ms)
pwm_PinA.duty_u16(0) # Turn off the pulse
time.sleep_ms(delay_ms)
pwm_PinB.duty_u16(0) # Turn off the pulse
time.sleep_ms(delay_ms)
# Example usage:
print("Rotating 2000 steps in one direction...")
rotate_stepper(2000, 0, delay_ms=2) # Rotate 2000 steps, direction 0, 2ms delay
time.sleep(1) # Wait for a second
print("Rotating 2000 steps in the other direction...")
rotate_stepper(2000, 1, delay_ms=2) # Rotate 2000 steps, direction 1, 2ms delay
# Optionally, stop the PWM if not needed continuously
# pwm_step.deinit()