How to use bipolar stepper motor using l298n module and raspberry pi pico w

Posted

in

by

The stepper motor that i have is a bipolar stepper motor.

On it one side there is information about it.

TYPE: 17PM-k310-33VS
NO.   T4508-03
    Minebea-Matsushita
    Motor Corporation
     Made in Thailand

It is a NEMA 17
17 stands for 1.7inches

Raspberry Pi Pico WL298N Module
GNDGND
GP0IN1
GP1IN2
GP2IN3
GP3IN4

The two coils pair are found using the multimeter in resistance mode.

Since I am using a regular motor driver. I cannot do the micro stepping.
But even with micro stepping, it can do a lot of stuff.

So there are two coil pair.
step angle of 1.8o degrees.

So to make a 360o
we need 360o / 1.8o = 200 steps

So we can make a full rotation with 200 steps of 1.8 degrees each.
This is what is known as the full step.
In full step, we only excite 1 pole at a time. There are two poles per coil.

We can excite two poles at a time. Which will half the step angle to 0.9 degrees.
The following is the table I have made to see how many steps I will be made by employing a 0.9 deg angle. It is only up to 300 steps or 270 deg. You can calculate from then on.

Micropython Code

from machine import Pin
import utime
motor_pins = [Pin(0, Pin.OUT), Pin(1, Pin.OUT), Pin(2, Pin.OUT), Pin(3, Pin.OUT)]
step_sequence = [
    [1,0,0,0],#1
    [1,0,1,0],#13
    [0,0,1,0],#3
    [0,1,1,0],#23
    [0,1,0,0],#2
    [0,1,0,1],#24
    [0,0,0,1],#4
    [1,0,0,1]#41  
]
off_seq = [(0,0,0,0)]
length_step_sequence = len(step_sequence)
one_rotation_length = 400/length_step_sequence
step_delay = (1/1000)*10 #ms
def step_off():
    #print("step off")
    motor_pins[0].value(0)
    motor_pins[1].value(0)
    motor_pins[2].value(0)
    motor_pins[3].value(0)
    utime.sleep(step_delay)
'''
Function Name: move_step
Description:
It takes the step sequence and assigns the motor pins to the value
according to the step sequence.
It moves one step seqence at a time.
For a half step sequence
each step will be 0.9 degrees.
For a full step sequence
each step will be 1.8 degrees.
'''
def move_step(seq):
    ygh = seq
    #print(ygh)
    for step1,pins in zip(ygh,motor_pins):
        pins.value(step1)
'''
Function Name: move one step
Description:
It moves all the steps in the sequence.
For a half wave steps => 8 * 0.9 = 7.2 deg
For a full wave steps => 4 * 1.8 = 7.2 deg
'''
def move_one_step(forward,reverse):
    for i in range(0,length_step_sequence,1):
        if forward == 1:
            move_step((step_sequence[i]))
        elif reverse == 1:
            move_step(reversed(step_sequence[i]))
        utime.sleep(step_delay)
def rotation(steps,forward,reverse):
    
    if forward == 1:
        for i in range(steps):
            move_one_step(1,0)
            print("Forward steps: ",steps)
    elif reverse == 1:
        for i in range(steps):
            move_one_step(0,1)
            print("Reverse steps: ",steps)
    
        #step_off()

'''
Half step calculations
8 Steps of 0.9 deg each.
total degree of 8 steps => 8 * 0.9 = 7.2
(8 step sequence) * (50 repeated steps) * 0.9 deg = 360
So, a total of 400 steps are required to make 360 degree.
7.2 deg x (50 repeated steps) = 360 degrees
7.2 deg x 25 = 180 degree
'''
while True:
    rotation(25,1,0) # move 180 forward(CW) 
    utime.sleep(1)
    rotation(50,0,1) # move 366 reverse (CCW)
    utime.sleep(1)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *