Overview
Demonstrates the control of a unipolar stepper motor. Without a ready-made H-bridge module, the bipolar stepper motor does not experiment.
There is no use of the stepper library, rough primitive drive with IO, more understanding of stepper motor drive.
Example program full-step driver
----------------------------------------------------------------------------//Unipolarsteppertest_ fullstep.ino////Created 2015-06-27//by Seesea <seesea2517#gmail#com>////////unipolar stepper Motor developes Magnetic Full-Step drive mode Test////////via ULN2003 to control , Arduino each IO port input, the corresponding output to the motor, because the uln2003 is an open collector output, so the motor public termination high level//------------------------------------------------ ----------------------------const unsigned char pins[] = {8, 9, ten,};const unsigned char pinnum = sizeof (Pins)/SI Zeof (Pins[0]); const unsigned char delayms = 10; Per-step action interval, control speed const char DIR = 1; The plus or minus one is used to control the direction of rotation void setup () {for (unsigned char i = 0; i < Pinnum; ++i) {Pinmode (pins[i], OUTPUT); Digitalwrite (Pins[i], low); }}//The pin is rotated each time it enters the function, and after a high level on the rotated pin, the uln2003 is reversed to a low level to the motor Power Void loop () {static unsigned char pulsepin = 0; Digitalwrite (Pins[pulsepin], high); Delay (delayms); Digitalwrite (Pins[pulsepin], low); Pulsepin = (Pulsepin + dir + pinnum)% Pinnum;}
Half-Step Drive
----------------------------------------------------------------------------//Unipolarsteppertest_ halfstep.ino////Created 2015-06-28//by Seesea <seesea2517#gmail#com>//////unipolar stepper Motor developes Magnetic Half-step drive test//use two ways to achieve, A control sequence using an array, a use of algorithms to achieve/////through the uln2003 to control, Arduino each IO port input, the corresponding output to the motor, because uln2003 is open collector output, so the motor public terminal High level//---------- ------------------------------------------------------------------const unsigned char pins[] = {8, 9, ten,};const uns igned char pinnum = sizeof (Pins)/sizeof (pins[0]); const unsigned char delayms = 10; Each action interval, the control speed const char DIR = 1; Plus or minus one to control rotation Direction const unsigned char controlseq[] = {0x08, 0x0C, 0x04, 0x06, 0x02, 0x03, 0x01, 0x09}; Control sequence: The two-pin const unsigned char pinmask[] = {0x01, 0x02, 0x04, 0x08} in the case of a low four-bit representation of the 4 pins in the pins that need to be energized in a single action; Pin-corresponding Mask const unsigned char seqNum = sizeof (CONTROLSEQ)/sizeof (controlseq[0]);//If the control sequence is changed to this, it becomes the original developes magnetic whole step forward The way: const unsigned char controlseq[] = {0x08, 0x04, 0x02, 0x01};//if the control sequence is changed to this, it becomes the way of the double phase excitation whole step forward: const unsigned char controlseq[] = {0x0C, 0x06, 0x03, 0x09};//Half-step drive implemented using control sequence method void Halfstep_controlseq () {static unsigned char seqindex = 0;//current sequence//emitting high level after uln2003 inverse-to-low power for complex, non-regular ways Flat to motor power on for (unsigned char i = 0; i < Pinnum; ++i) {Digitalwrite (Pins[i], (Controlseq[seqindex] & PINM Ask[i])? High:low); } Seqindex = (Seqindex + dir + seqNum)% SeqNum; Delay (delayms);} Using the algorithm to achieve the half-step drive//half-step drive operation is actually also a certain regularity, so you can also use a certain algorithm to implement void Halfstep_algrothm () {static unsigned char pulsePin1 = 0; static unsigned char pulsePin2 = 0; Digitalwrite (Pins[pulsepin1], high); Digitalwrite (Pins[pulsepin2], high); Delay (delayms); Digitalwrite (Pins[pulsepin1], low); Digitalwrite (Pins[pulsepin2], low); Algorithm implementation///two PIN index according to the law (the forward direction is the Dir standard, if dir is negative, the backward direction as forward)://-When the two pins the same time, pin1 forward//-when two pins are different, pin2 forward if (pulsePin1 = = pulsePin2) PulsePin1 = (pulsePin1 + dir + pinnum)% Pinnum; else PulsePin2 = (pulsePin2 + dir + pinnum)% Pinnum;} void Setup () {serial.begin (9600); for (unsigned char i = 0; i < Pinnum; ++i) {Pinmode (pins[i], OUTPUT); Digitalwrite (Pins[i], low); }}void Loop () {halfstep_controlseq (); Halfstep_algrothm ();}
Experimental photos
Arduino Introductory Program Sample Stepper motor (2015-06-28)