To make a stepper motor work it needs to be provided with a sequence of high and low signals to each of the four inputs in a correct sequence of high and low signals the motor will turn rotating the spindle, this motor can turn clockwise and also anti clockwise by reversing the sequence.
I cannot remember the coding I originally used, but Matt Hawkins over at raspberry-pi-spy has written an excellent short python script which is excellent to play with to get a good understanding of how a, the script works and b, the stepper motor works.
Thanks Matt for the following script:
# Name: Stepper Motor## Author: matt.hawkins## Created: 11/07/2012# Copyright: (c) matt.hawkins 2012#-----------------------------------#!/usr/bin/env python# Import required librariesimport timeimport RPi.GPIO as GPIO# Use BCM GPIO references# instead of physical pin numbersGPIO.setmode(GPIO.BCM)# Define GPIO signals to use# Pins 18,22,24,26# GPIO24,GPIO25,GPIO8,GPIO7StepPins = [24,25,8,7]# Set all pins as outputfor pin in StepPins: print "Setup pins" GPIO.setup(pin,GPIO.OUT) GPIO.output(pin, False)# Define some settingsStepCounter = 0WaitTime = 0.5# Define simple sequenceStepCount1 = 4Seq1 = []Seq1 = range(0, StepCount1)Seq1[0] = [1,0,0,0]Seq1[1] = [0,1,0,0]Seq1[2] = [0,0,1,0]Seq1[3] = [0,0,0,1]# Define advanced sequence# as shown in manufacturers datasheetStepCount2 = 8Seq2 = []Seq2 = range(0, StepCount2)Seq2[0] = [1,0,0,0]Seq2[1] = [1,1,0,0]Seq2[2] = [0,1,0,0]Seq2[3] = [0,1,1,0]Seq2[4] = [0,0,1,0]Seq2[5] = [0,0,1,1]Seq2[6] = [0,0,0,1]Seq2[7] = [1,0,0,1]# Choose a sequence to useSeq = Seq1StepCount = StepCount1# Start main loopwhile 1==1: for pin in range(0, 4): xpin = StepPins[pin] if Seq[StepCounter][pin]!=0: print " Step %i Enable %i" %(StepCounter,xpin) GPIO.output(xpin, True) else: GPIO.output(xpin, False) StepCounter += 1 # If we reach the end of the sequence # start again if (StepCounter==StepCount): StepCounter = 0 if (StepCounter<0): StepCounter = StepCount # Wait before moving on time.sleep(WaitTime)5v and gnd connections should be obvious while the other four go to pins 18, 22, 24, 26. (Ch1, ch2, ch3, ch4) |

No comments:
Post a Comment
Please feel free to comment would love to hear your ideas.