From 9d593e110a6a35f8eeb4fd855d1bc437f6fe4cba Mon Sep 17 00:00:00 2001 From: Tuneer Saha <111687370+tuneersaha@users.noreply.github.com> Date: Fri, 22 Dec 2023 19:07:00 +0000 Subject: [PATCH 1/5] This commit enables the stepper library to be able to drive two 4-pin stepper motors together both rolling at opposite directions to give effects like front wheel drive or rear wheel drive -- useful for making rovers on Arduino using Stepper Motors --- src/Stepper.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++----- src/Stepper.h | 24 +++++++----- 2 files changed, 103 insertions(+), 19 deletions(-) diff --git a/src/Stepper.cpp b/src/Stepper.cpp index 148de03..77bc75c 100644 --- a/src/Stepper.cpp +++ b/src/Stepper.cpp @@ -34,9 +34,9 @@ * reduced from 4 to 2 for the unipolar and bipolar motors. * * A slightly modified circuit around a Darlington transistor array or an - * L293 H-bridge connects to only 2 microcontroller pins, inverts the signals + * L293 H-bridge connects to only 2 microcontroler pins, inverts the signals * received, and delivers the 4 (2 plus 2 inverted ones) output signals - * required for driving a stepper motor. Similarly the Arduino motor shield's + * required for driving a stepper motor. Similarly the Arduino motor shields * 2 direction pins may be used. * * The sequence of control signals for 5 phase, 5 control wires is as follows: @@ -61,7 +61,7 @@ * 3 0 1 0 1 * 4 1 0 0 1 * - * The sequence of control signals for 2 control wires is as follows + * The sequence of controls signals for 2 control wires is as follows * (columns C1 and C2 from above): * * Step C0 C1 @@ -72,7 +72,7 @@ * * The circuits can be found at * - * https://docs.arduino.cc/learn/electronics/stepper-motors#circuit + * http://www.arduino.cc/en/Tutorial/Stepper */ #include "Arduino.h" @@ -86,7 +86,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2) { this->step_number = 0; // which step the motor is on this->direction = 0; // motor direction - this->last_step_time = 0; // timestamp in us of the last step taken + this->last_step_time = 0; // time stamp in us of the last step taken this->number_of_steps = number_of_steps; // total number of steps for this motor // Arduino pins for the motor control connection: @@ -116,7 +116,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, { this->step_number = 0; // which step the motor is on this->direction = 0; // motor direction - this->last_step_time = 0; // timestamp in us of the last step taken + this->last_step_time = 0; // time stamp in us of the last step taken this->number_of_steps = number_of_steps; // total number of steps for this motor // Arduino pins for the motor control connection: @@ -148,7 +148,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, { this->step_number = 0; // which step the motor is on this->direction = 0; // motor direction - this->last_step_time = 0; // timestamp in us of the last step taken + this->last_step_time = 0; // time stamp in us of the last step taken this->number_of_steps = number_of_steps; // total number of steps for this motor // Arduino pins for the motor control connection: @@ -169,6 +169,41 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, this->pin_count = 5; } +/*for 8 pins at once so that two motors at opposite directions can run parallely at opposite direction + to create effects like front wheel drive or back wheel drive, since arduino has a single channel*/ +Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, + int motor_pin_3, int motor_pin_4, + int motor_pin_5, int motor_pin_6, + int motor_pin_7, int motor_pin_8) +{ + this->step_number = 0; // which step the motor is on + this->direction = 0; // motor direction + this->last_step_time = 0; // timestamp in us of the last step taken + this->number_of_steps = number_of_steps; // total number of steps for this motor + // Arduino pins for the motor control connection: + this->motor_pin_1 = motor_pin_1; + this->motor_pin_2 = motor_pin_2; + this->motor_pin_3 = motor_pin_3; + this->motor_pin_4 = motor_pin_4; + this->motor_pin_5 = motor_pin_5; + this->motor_pin_6 = motor_pin_6; + this->motor_pin_7 = motor_pin_7; + this->motor_pin_8 = motor_pin_8; + + // setup the pins on the microcontroller: + pinMode(this->motor_pin_1, OUTPUT); + pinMode(this->motor_pin_2, OUTPUT); + pinMode(this->motor_pin_3, OUTPUT); + pinMode(this->motor_pin_4, OUTPUT); + pinMode(this->motor_pin_5, OUTPUT); + pinMode(this->motor_pin_6, OUTPUT); + pinMode(this->motor_pin_7, OUTPUT); + pinMode(this->motor_pin_8, OUTPUT); + + // pin_count is used by the stepMotor() method: + this->pin_count = 8; +} + /* * Sets the speed in revs per minute */ @@ -222,8 +257,6 @@ void Stepper::step(int steps_to_move) stepMotor(this->step_number % 10); else stepMotor(this->step_number % 4); - } else { - yield(); } } } @@ -282,6 +315,51 @@ void Stepper::stepMotor(int thisStep) } } + if (this->pin_count == 8) { + switch (thisStep) { + case 0: // 1010 + digitalWrite(motor_pin_1, HIGH); + digitalWrite(motor_pin_2, LOW); + digitalWrite(motor_pin_3, HIGH); + digitalWrite(motor_pin_4, LOW); + digitalWrite(motor_pin_5, LOW); + digitalWrite(motor_pin_6, HIGH); + digitalWrite(motor_pin_7, HIGH); + digitalWrite(motor_pin_8, LOW); + break; + case 1: // 0110 + digitalWrite(motor_pin_1, LOW); + digitalWrite(motor_pin_2, HIGH); + digitalWrite(motor_pin_3, HIGH); + digitalWrite(motor_pin_4, LOW); + digitalWrite(motor_pin_5, HIGH); + digitalWrite(motor_pin_6, LOW); + digitalWrite(motor_pin_7, HIGH); + digitalWrite(motor_pin_8, LOW); + break; + case 2: //0101 + digitalWrite(motor_pin_1, LOW); + digitalWrite(motor_pin_2, HIGH); + digitalWrite(motor_pin_3, LOW); + digitalWrite(motor_pin_4, HIGH); + digitalWrite(motor_pin_5, HIGH); + digitalWrite(motor_pin_6, LOW); + digitalWrite(motor_pin_7, LOW); + digitalWrite(motor_pin_8, HIGH); + break; + case 3: //1001 + digitalWrite(motor_pin_1, HIGH); + digitalWrite(motor_pin_2, LOW); + digitalWrite(motor_pin_3, LOW); + digitalWrite(motor_pin_4, HIGH); + digitalWrite(motor_pin_5, LOW); + digitalWrite(motor_pin_6, HIGH); + digitalWrite(motor_pin_7, LOW); + digitalWrite(motor_pin_8, HIGH); + break; + } + } + if (this->pin_count == 5) { switch (thisStep) { case 0: // 01101 @@ -364,4 +442,4 @@ void Stepper::stepMotor(int thisStep) int Stepper::version(void) { return 5; -} +} \ No newline at end of file diff --git a/src/Stepper.h b/src/Stepper.h index b5578b4..80029be 100644 --- a/src/Stepper.h +++ b/src/Stepper.h @@ -34,9 +34,9 @@ * reduced from 4 to 2 for the unipolar and bipolar motors. * * A slightly modified circuit around a Darlington transistor array or an - * L293 H-bridge connects to only 2 microcontroller pins, inverts the signals + * L293 H-bridge connects to only 2 microcontroler pins, inverts the signals * received, and delivers the 4 (2 plus 2 inverted ones) output signals - * required for driving a stepper motor. Similarly the Arduino motor shield's + * required for driving a stepper motor. Similarly the Arduino motor shields * 2 direction pins may be used. * * The sequence of control signals for 5 phase, 5 control wires is as follows: @@ -61,7 +61,7 @@ * 3 0 1 0 1 * 4 1 0 0 1 * - * The sequence of control signals for 2 control wires is as follows + * The sequence of controls signals for 2 control wires is as follows * (columns C1 and C2 from above): * * Step C0 C1 @@ -72,7 +72,7 @@ * * The circuits can be found at * - * https://docs.arduino.cc/learn/electronics/stepper-motors#circuit + * http://www.arduino.cc/en/Tutorial/Stepper */ // ensure this library description is only included once @@ -89,6 +89,10 @@ class Stepper { Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4, int motor_pin_5); + Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, + int motor_pin_3, int motor_pin_4, + int motor_pin_5, int motor_pin_6, + int motor_pin_7, int motor_pin_8); // speed setter method: void setSpeed(long whatSpeed); @@ -102,7 +106,7 @@ class Stepper { void stepMotor(int this_step); int direction; // Direction of rotation - unsigned long step_delay; // delay between steps, in us, based on speed + unsigned long step_delay; // delay between steps, in ms, based on speed int number_of_steps; // total number of steps this motor can take int pin_count; // how many pins are in use. int step_number; // which step the motor is on @@ -112,10 +116,12 @@ class Stepper { int motor_pin_2; int motor_pin_3; int motor_pin_4; - int motor_pin_5; // Only 5 phase motor + int motor_pin_5; + int motor_pin_6; + int motor_pin_7; + int motor_pin_8; // Only 5 phase motor - unsigned long last_step_time; // timestamp in us of when the last step was taken + unsigned long last_step_time; // time stamp in us of when the last step was taken }; -#endif - +#endif \ No newline at end of file From bacdc42fd0d08a54d30e00a50272d5086e3c5ef7 Mon Sep 17 00:00:00 2001 From: Tuneer Saha <111687370+tuneersaha@users.noreply.github.com> Date: Fri, 22 Dec 2023 19:22:04 +0000 Subject: [PATCH 2/5] Some text editing --- src/Stepper.cpp | 16 +++++++++------- src/Stepper.h | 18 +++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Stepper.cpp b/src/Stepper.cpp index 77bc75c..8570c35 100644 --- a/src/Stepper.cpp +++ b/src/Stepper.cpp @@ -34,9 +34,9 @@ * reduced from 4 to 2 for the unipolar and bipolar motors. * * A slightly modified circuit around a Darlington transistor array or an - * L293 H-bridge connects to only 2 microcontroler pins, inverts the signals + * L293 H-bridge connects to only 2 microcontroller pins, inverts the signals * received, and delivers the 4 (2 plus 2 inverted ones) output signals - * required for driving a stepper motor. Similarly the Arduino motor shields + * required for driving a stepper motor. Similarly the Arduino motor shield's * 2 direction pins may be used. * * The sequence of control signals for 5 phase, 5 control wires is as follows: @@ -61,7 +61,7 @@ * 3 0 1 0 1 * 4 1 0 0 1 * - * The sequence of controls signals for 2 control wires is as follows + * The sequence of control signals for 2 control wires is as follows * (columns C1 and C2 from above): * * Step C0 C1 @@ -72,7 +72,7 @@ * * The circuits can be found at * - * http://www.arduino.cc/en/Tutorial/Stepper + * https://docs.arduino.cc/learn/electronics/stepper-motors#circuit */ #include "Arduino.h" @@ -86,7 +86,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2) { this->step_number = 0; // which step the motor is on this->direction = 0; // motor direction - this->last_step_time = 0; // time stamp in us of the last step taken + this->last_step_time = 0; // timestamp in us of the last step taken this->number_of_steps = number_of_steps; // total number of steps for this motor // Arduino pins for the motor control connection: @@ -116,7 +116,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, { this->step_number = 0; // which step the motor is on this->direction = 0; // motor direction - this->last_step_time = 0; // time stamp in us of the last step taken + this->last_step_time = 0; // timestamp in us of the last step taken this->number_of_steps = number_of_steps; // total number of steps for this motor // Arduino pins for the motor control connection: @@ -148,7 +148,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, { this->step_number = 0; // which step the motor is on this->direction = 0; // motor direction - this->last_step_time = 0; // time stamp in us of the last step taken + this->last_step_time = 0; // timestamp in us of the last step taken this->number_of_steps = number_of_steps; // total number of steps for this motor // Arduino pins for the motor control connection: @@ -257,6 +257,8 @@ void Stepper::step(int steps_to_move) stepMotor(this->step_number % 10); else stepMotor(this->step_number % 4); + } else { + yield(); } } } diff --git a/src/Stepper.h b/src/Stepper.h index 80029be..7873ab1 100644 --- a/src/Stepper.h +++ b/src/Stepper.h @@ -34,9 +34,9 @@ * reduced from 4 to 2 for the unipolar and bipolar motors. * * A slightly modified circuit around a Darlington transistor array or an - * L293 H-bridge connects to only 2 microcontroler pins, inverts the signals + * L293 H-bridge connects to only 2 microcontroller pins, inverts the signals * received, and delivers the 4 (2 plus 2 inverted ones) output signals - * required for driving a stepper motor. Similarly the Arduino motor shields + * required for driving a stepper motor. Similarly the Arduino motor shield's * 2 direction pins may be used. * * The sequence of control signals for 5 phase, 5 control wires is as follows: @@ -61,7 +61,7 @@ * 3 0 1 0 1 * 4 1 0 0 1 * - * The sequence of controls signals for 2 control wires is as follows + * The sequence of control signals for 2 control wires is as follows * (columns C1 and C2 from above): * * Step C0 C1 @@ -72,7 +72,7 @@ * * The circuits can be found at * - * http://www.arduino.cc/en/Tutorial/Stepper + * https://docs.arduino.cc/learn/electronics/stepper-motors#circuit */ // ensure this library description is only included once @@ -106,7 +106,7 @@ class Stepper { void stepMotor(int this_step); int direction; // Direction of rotation - unsigned long step_delay; // delay between steps, in ms, based on speed + unsigned long step_delay; // delay between steps, in us, based on speed int number_of_steps; // total number of steps this motor can take int pin_count; // how many pins are in use. int step_number; // which step the motor is on @@ -116,12 +116,12 @@ class Stepper { int motor_pin_2; int motor_pin_3; int motor_pin_4; - int motor_pin_5; + int motor_pin_5; // Only 5 phase motor int motor_pin_6; int motor_pin_7; - int motor_pin_8; // Only 5 phase motor + int motor_pin_8; // Defined till 8 pins because 4-pin x2 - unsigned long last_step_time; // time stamp in us of when the last step was taken + unsigned long last_step_time; // timestamp in us of when the last step was taken }; -#endif \ No newline at end of file +#endif From d43655b3e14f58c1e5d010e7ac7e295eb235e300 Mon Sep 17 00:00:00 2001 From: Tuneer Saha <111687370+tuneersaha@users.noreply.github.com> Date: Sat, 23 Dec 2023 20:42:41 +0000 Subject: [PATCH 3/5] Parallely ==> Parallelly (Spell Fix) --- src/Stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stepper.cpp b/src/Stepper.cpp index 8570c35..2a2f3cd 100644 --- a/src/Stepper.cpp +++ b/src/Stepper.cpp @@ -169,7 +169,7 @@ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, this->pin_count = 5; } -/*for 8 pins at once so that two motors at opposite directions can run parallely at opposite direction +/*for 8 pins at once so that two motors at opposite directions can run parallelly at opposite direction to create effects like front wheel drive or back wheel drive, since arduino has a single channel*/ Stepper::Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4, From 23acb40a88e50fe619dc6748bbb3e0a4ade6d362 Mon Sep 17 00:00:00 2001 From: Tuneer Saha <111687370+tuneersaha@users.noreply.github.com> Date: Sat, 30 Dec 2023 23:22:23 +0530 Subject: [PATCH 4/5] Update README.adoc From 1e666b31e7706735cc5003226aaddf18ab74ef35 Mon Sep 17 00:00:00 2001 From: Tuneer Saha <111687370+tuneersaha@users.noreply.github.com> Date: Fri, 19 Jan 2024 09:48:46 +0000 Subject: [PATCH 5/5] another try --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 55b91a8..a098bc2 100644 --- a/README.adoc +++ b/README.adoc @@ -10,7 +10,7 @@ image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/ This library allows you to control unipolar or bipolar stepper motors. To use it you will need a stepper motor, and the appropriate hardware to control it. For more information about this library please visit us at -http://www.arduino.cc/en/Reference/{repository-name} +http://www.arduino.cc/en/Reference/{repository-name} == License ==