This is a library that modifies the Arduino 'Stepper' library to drive a step motor asynchronously.
Detailed explanation (Korean) : [Arduino] StepperAsync5 - 비동기 스탭 모터 라이브러리
The existing 'Stepper' library operates synchronously, so other operations cannot be performed while the stepper motor is operating.
This library corrects these disadvantages and allows other operations while the stepper motor is running.
- Same declaration structure as 'Stepper' library
- Same usage as 'Stepper' library
- Operate asynchronously by operating without stopping the main 'loop'
- Multiple stepper motors or other operations can be performed simultaneously
- Download the file from Releases or
- Create 'StepperAsync5.h' and 'StepperAsync5.cpp' and copy the source.
- (Arduino IDE 2.x or later) Select 'Sketch > Include Library > Manage Libraries...' in 'Arduino IDE' to open 'Library Manager' and install 'Stepper Async 5'.
Follow the instructions below to install.
Tested on Arduino 1.8.19
(This process is unnecessary if you have installed with 'Library Manager'.)
-
Create 'StepperAsync5' folder in 'libraries' folder of Arduino IDE
-
Insert 'StepperAsync5.h', 'StepperAsync5.cpp'.
You can use 'StepperAsync5' by running 'Arduino IDE' and adding the following code.
#include <StepperAsync5.h>
Put the code below in your sketch to test it.
#include <StepperAsync5.h>
int LED1 = A0;
StepperAsync5 stepper(200, 12, 11, 10, 9);
StepperAsync5 stepper2(200, 7, 6, 5, 4);
void setup()
{
Serial.begin(9600);
pinMode(LED1, OUTPUT);
stepper.setSpeed(30);
stepper2.setSpeed(60);
}
void loop()
{
if (Serial.available())
{
int steps = Serial.parseInt();
if(steps != 0)
{
digitalWrite(LED1, HIGH);
stepper.setStep(steps);
digitalWrite(LED1, LOW);
stepper2.setStep(steps);
digitalWrite(LED1, HIGH);
//stepper.setStep(200);
//stepper2.setStep(200);
Serial.print("steps : ");
Serial.println(steps);
delay(100);
digitalWrite(LED1, LOW);
}
}
stepper.moveStep();
stepper2.moveStep();
//Serial.print("Is Move - stepper : ");
//Serial.print(stepper.MoveOnIs);
//Serial.print(", stepper2 : ");
//Serial.println(stepper2.MoveOnIs);
}
Name | Description |
---|---|
StepperAsync5(int number_of_steps, int motor_pin_1, int motor_pin_2) | Generator used for 2-wire stepper motor @param number_of_steps the number of steps in one revolution of your motor. @param motor_pin_1 Pin number 1 connected to the motor @param motor_pin_2 Pin number 2 connected to the motor |
StepperAsync5(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4) | Generator used for 4-wire and 6-wire stepper motors @param number_of_steps the number of steps in one revolution of your motor. @param motor_pin_1 Pin number 1 connected to the motor @param motor_pin_2 Pin number 2 connected to the motor @param motor_pin_3 Pin number 3 connected to the motor @param motor_pin_4 Pin number 4 connected to the motor |
StepperAsync5(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4, int motor_pin_5) | Generator used for 8-wire stepper motor @param number_of_steps the number of steps in one revolution of your motor. @param motor_pin_1 Pin number 1 connected to the motor @param motor_pin_2 Pin number 2 connected to the motor @param motor_pin_3 Pin number 3 connected to the motor @param motor_pin_4 Pin number 4 connected to the motor @param motor_pin_5 Pin number 5 connected to the motor |
void setSpeed(long whatSpeed) | This function sets the motor speed in rotations per minute (RPMs). @param whatSpeed the speed at which the motor should turn in rotations per minute |
void setStep(int number_of_steps) | Commands the motor to turn by a set number of steps. A function that corresponds to 'stop()' in the 'Stepper' library, but does not rotate directly. 'moveStep()' must be called to rotate. @param number_of_steps the number of steps to turn the motor. Positive integer to turn one direction, negative integer to turn the other. |
void moveStep() | Rotate by the set number of steps. You must call this method inside 'loop()'. |
void version() | Print the baseline version of this library. Libraries are separated according to the standard version, so this library is fixed to '5'. |
MoveOnIs | Whether the motor is running now or not moving=true, if not moving=false |
- Add 'MoveOnIs'
- Renamed 'StepperMulti5' to 'StepperAsync5'
'Fork' the project to create a 'new branch' and then 'pull request'.
A list of non-updating contributors can be found at contributors.
GNU LESSER GENERAL PUBLIC LICENSE
== 'Stepper' library ==
Copyright (c) Arduino LLC. All right reserved.
Copyright (c) Sebastian Gassner. All right reserved.
Copyright (c) Noah Shibley. All right reserved.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA