ESP_IOT v2.5
IOT ESP Coding
Stepper.h
Go to the documentation of this file.
1/*
2 * Stepper.h - Stepper library for Wiring/Arduino - Version 1.1.0
3 *
4 * Original library (0.1) by Tom Igoe.
5 * Two-wire modifications (0.2) by Sebastian Gassner
6 * Combination version (0.3) by Tom Igoe and David Mellis
7 * Bug fix for four-wire (0.4) by Tom Igoe, bug fix from Noah Shibley
8 * High-speed stepping mod by Eugene Kozlenko
9 * Timer rollover fix by Eugene Kozlenko
10 * Five phase five wire (1.1.0) by Ryan Orendorff
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 *
26 *
27 * Drives a unipolar, bipolar, or five phase stepper motor.
28 *
29 * When wiring multiple stepper motors to a microcontroller, you quickly run
30 * out of output pins, with each motor requiring 4 connections.
31 *
32 * By making use of the fact that at any time two of the four motor coils are
33 * the inverse of the other two, the number of control connections can be
34 * reduced from 4 to 2 for the unipolar and bipolar motors.
35 *
36 * A slightly modified circuit around a Darlington transistor array or an
37 * L293 H-bridge connects to only 2 microcontroler pins, inverts the signals
38 * received, and delivers the 4 (2 plus 2 inverted ones) output signals
39 * required for driving a stepper motor. Similarly the Arduino motor shields
40 * 2 direction pins may be used.
41 *
42 * The sequence of control signals for 5 phase, 5 control wires is as follows:
43 *
44 * Step C0 C1 C2 C3 C4
45 * 1 0 1 1 0 1
46 * 2 0 1 0 0 1
47 * 3 0 1 0 1 1
48 * 4 0 1 0 1 0
49 * 5 1 1 0 1 0
50 * 6 1 0 0 1 0
51 * 7 1 0 1 1 0
52 * 8 1 0 1 0 0
53 * 9 1 0 1 0 1
54 * 10 0 0 1 0 1
55 *
56 * The sequence of control signals for 4 control wires is as follows:
57 *
58 * Step C0 C1 C2 C3
59 * 1 1 0 1 0
60 * 2 0 1 1 0
61 * 3 0 1 0 1
62 * 4 1 0 0 1
63 *
64 * The sequence of controls signals for 2 control wires is as follows
65 * (columns C1 and C2 from above):
66 *
67 * Step C0 C1
68 * 1 0 1
69 * 2 1 1
70 * 3 1 0
71 * 4 0 0
72 *
73 * The circuits can be found at
74 *
75 * http://www.arduino.cc/en/Tutorial/Stepper
76 */
77
78// ensure this library description is only included once
79#ifndef Stepper_h
80#define Stepper_h
81
82// library interface description
83class Stepper {
84 public:
85 // constructors:
86 Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2);
87 Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
88 int motor_pin_3, int motor_pin_4);
89 Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2,
90 int motor_pin_3, int motor_pin_4,
91 int motor_pin_5);
92
93 // speed setter method:
94 void setSpeed(long whatSpeed);
95
96 //! 8.14.25 set speed and number_of_steps
97 void setSpeedSteps(long whatSpeed, int number_of_steps);
98
99 // mover method:
100 void step(int number_of_steps);
101
102 int version(void);
103
104 private:
105 void stepMotor(int this_step);
106
107 int direction; // Direction of rotation
108 unsigned long step_delay; // delay between steps, in ms, based on speed
109 int number_of_steps; // total number of steps this motor can take
110 int pin_count; // how many pins are in use.
111 int step_number; // which step the motor is on
112
113 // motor pin numbers:
114 int motor_pin_1;
115 int motor_pin_2;
116 int motor_pin_3;
117 int motor_pin_4;
118 int motor_pin_5; // Only 5 phase motor
119
120 unsigned long last_step_time; // time stamp in us of when the last step was taken
121};
122
123#endif
124
void setSpeedSteps(long whatSpeed, int number_of_steps)
8.14.25 set speed and number_of_steps
Definition: Stepper.cpp:187
void step(int number_of_steps)
Definition: Stepper.cpp:198
int version(void)
Definition: Stepper.cpp:376
Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2)
Definition: Stepper.cpp:85
void setSpeed(long whatSpeed)
Definition: Stepper.cpp:175