Scratch Controlling the GPIO Pins on a Raspberry Pi
Part 3 of 4
Stepper Motor Control
WARNING: NO MOTOR SHOULD EVER BE CONNECTED DIRECTLY TO A RASPBERRY PI
However, if you would like to build a neat little vehicular robot then you can do so by connecting up a pair of cheap Stepper Motors through a couple of very cheap ULN2003s.
The cheap 5V steppers that are widely available (BY28) don’t turn very fast (maximum about 12 RPM) which actually makes them idea as beginners motors as your vehicle won’t run away during testing
These motors have 5 connections 1 for power and the rest to control the stepping. (Their technical name is 5 Wire Unipolar Stepper Motor)
StepperA must be connected (via a ULN2003 buffer of course) to pins 11,12,13 and 15 – Stepper B must be connected to pins 16,18,22 and 7.
With the cheap BY28 series – this means Orange,Yellow,Pink,Blue to 11,12,13 and 15 with the Red going to the 5V Pin2 or a separate motor 4.5-6V battery
You can then simply using variables MotorA and MotorB as before but this time they will each control 4 pins at a time.
The advantage of using stepper motors is that they can be just as easily stepped backwards as forwards. So to make MotorA go backwards at full speed simply use
As well as treating the stepper as a continously rotating motor, you can simply tell the stepper to change its “position” by a number of steps.
Note the use of change and not set
Advanced Stepper Control
Stepper motors need a delay between each step – this is currently set to 0.003 secs. You can control this value by using a variable called StepDelay.
You can also change the type of stepping mode from 2Coil (default value that gives maximum turning force) to 1Coil or HalfStep