How to Control Bipolar Stepper Motor in Raspberry pi
You want to drive a four-lead bipolar stepper motor using a Raspberry Pi. Today I show you How to Control Bipolar Stepper Motor in Raspberry piComponents Required :
This book will help you to gain more knowledge of Raspberry pi Software and Hardware Problems and Solutions
Raspberry Pi Cookbook
Circuit diagram :
Use an L293D H-Bridge driver chip. An H-Bridge is required to drive a stepper motor because, as the word bipolar suggests, the direction of current across the windings needs to be reversed, rather like driving a DC the motor in both directions L293D to control a bipolar stepper motor[/caption]
The motor used here, a 12V, is somewhat larger than the previous unipolar stepper motor example. The power for the motor itself is therefore supplied from an external power supply rather than from the Raspberry Pi.
Code Bipolar Stepper Motor Raspberry:
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))For more information on stepper motors—the different types and how they work—see Wikipedia, where you will also find a nice animated explanation of the activation pattern for driving the motor
No comments