How to Control Unipolar Stepper Motor in Raspberry pi
You want to drive a five-lead unipolar stepper motor using a Raspberry Pi. Today I show you How to Control Unipolar Stepper Motor in Raspberry pi Stepper motors use a cogged rotor and electromagnets to nudge the wheel around a step at a time Energizing the coils in a certain order drives the motor around. The number of steps that the stepper motor has in a 360-degree rotation is actually the number of teeth on the rotor.Components Required :
This book will help you to gain more knowledge of Raspberry pi Software and Hardware Problems and Solutions
Raspberry Pi Cookbook
Circuit diagram Stepper Motor Raspberry :
Using a ULN2803 to control a unipolar stepper motor
Use a ULN2803 Darlington driver chip on the breadboard. Stepper motors fit somewhere between DC motors and servo motors in the world of motor technologies. Like a regular DC motor, they can rotate continuously, but you can also very accurately position them by moving them a step at a time in either direction
the chip can be used to drive two such motors. To drive a second stepper motor, you will need to connect four more control pins from the GPIO connector to pins 5 to 8 of the ULN2803 and connect the second motor’s four pins to pins 11 to 14 of the ULN2803.
The 5V supply from the GPIO connector may work OK with a small stepper motor. If you experience problems with the Raspberry Pi crashing or need to use a bigger stepper motor, then use a separate supply for the
power to the motor.
Code Stepper Motor Raspberry Pi :
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
coil_A_1_pin = 18
coil_A_2_pin = 23
coil_B_1_pin = 24
coil_B_2_pin = 17
GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)
forward_seq = ['1010', '0110', '0101', '1001']
reverse_seq = list(forward_seq) # to copy the list
reverse_seq.reverse()
def forward(delay, steps):
for i in range(steps):
for step in forward_seq:
set_step(step)
time.sleep(delay)
def backwards(delay, steps):
for i in range(steps):
for step in reverse_seq:
set_step(step)
time.sleep(delay)
def set_step(step):
GPIO.output(coil_A_1_pin, step[0] == '1')
GPIO.output(coil_A_2_pin, step[1] == '1')
GPIO.output(coil_B_1_pin, step[2] == '1')
GPIO.output(coil_B_2_pin, step[3] == '1')
while True:
set_step('0000')
delay = raw_input("Delay between steps (milliseconds)?")
steps = raw_input("How many steps forward? ")
forward(int(delay) / 1000.0, int(steps))
set_step('0000')
steps = raw_input("How many steps backwards? ")
backwards(int(delay) / 1000.0, int(steps))
When you run the program, you will be prompted for a delay between steps. This should be 2 or more. You will then be prompted for the number of steps in each direction: delay between steps (milliseconds)?
2
How many steps forward?
100
How many steps backwards?
100
Delay between steps (milliseconds)?10
No comments