PyBoard and stepper motor

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
adamboho
Posts: 15
Joined: Fri Oct 10, 2014 4:27 pm

PyBoard and stepper motor

Post by adamboho » Thu Oct 23, 2014 10:03 pm

Hi everyone. This is just to show, how I use pyboard to control stepper motor.
Maybe someone will need it.

See it in action. https://www.youtube.com/watch?v=4XYBexi ... e=youtu.be

Code: Select all

import pyb

accel = pyb.Accel()

speed_x = 0

angle_x = 0

tim_x = pyb.Timer(1, freq=1)


def stepper_x(speed, angle):
    global speed_x
    global angle_x

    if angle_x != angle:

        if angle_x < angle:
            
            angle_x += 1

            pyb.Pin('X2', pyb.Pin.OUT_PP).low()
        
            pyb.Pin('X1', pyb.Pin.OUT_PP).high()
            pyb.Pin('X1', pyb.Pin.OUT_PP).low()

        if angle_x > angle:
            
            angle_x -= 1

            pyb.Pin('X2', pyb.Pin.OUT_PP).high()
        
            pyb.Pin('X1', pyb.Pin.OUT_PP).high()
            pyb.Pin('X1', pyb.Pin.OUT_PP).low()

        
    
    if speed_x != speed:
        tim_x.init(freq = speed)
        speed_x = speed




        
while True:
    x = accel.x()
    x = x * 3
    tim_x.callback(lambda t:stepper_x(200, x))
    
    pyb.delay(100)
    
    pyb.LED(3).on()

Any suggestions welcome.

riklaunim
Posts: 32
Joined: Fri Aug 22, 2014 5:42 pm

Re: PyBoard and stepper motor

Post by riklaunim » Fri Oct 24, 2014 6:35 am

I used slightly different solution for ULN2003 stepper motor controller, without the Timer class.

adamboho
Posts: 15
Joined: Fri Oct 10, 2014 4:27 pm

Re: PyBoard and stepper motor

Post by adamboho » Fri Oct 24, 2014 8:05 pm

Yes, that is fine but I want use USB_VCP() to receive commands to control the stepper motor, so pyb.delay() is no good, at least for me.

User avatar
yllumi
Posts: 37
Joined: Tue Aug 19, 2014 8:41 am
Location: Bandung, West Java, Indonesia
Contact:

Re: PyBoard and stepper motor

Post by yllumi » Wed May 27, 2015 7:33 am

I am using ULD2003 and trying the code from @riklaunim. It works but the rotation is too slow, even after I change the delay to 2ms. How can I raise the speed?

Post Reply