Helly Everyone! I was wondering if it's possible to use the attach() and detach() function on a Stepper Motor (NEMA17 12V 350mA) with an Easy Driver (Gikfun EasyDriver Shield Stepper Motor Driver V44 A3967)? If so can you give me an example code of this process? It would be so helpful if you do! ![]()
There are no attach() and detach() functions. There might be attach() and detach() methods in some class, but what that class might be is a mystery.
I was wondering if it's possible to use the attach() and detach() function on a Stepper Motor
Why do you want to do that ?
I'm using a program where the stepper motor moves a cart with cup and bowl to a position; holds that position while a servo motor to help dispense cereal and fluid. I want the stepper motor to move in three positions for each servo motor then resets itself to its initial position and repeat the process.
Here is the code I'm working with at the moment.
#include <Servo.h>
#include <Stepper.h>
Servo myservo1; // Cereal Servo Motor
Servo myservo2; // Fluid 1 Servo Motor
Servo myservo3; // Fluid 2 Servo Motor
void setup() {
 myservo1.attach(2); // attaches the servo on pin 2 to the servo object
 myservo2.attach(3); // attaches the servo on pin 3 to the servo object
 myservo3.attach(5); // attaches the servo on pin 5 to the servo object
}
void loop() {
Â
// Step Motor Code Move to Postition 1
// WORK IN PROGRESS
Â
// Code To Turn The Cereal Dispenser
myservo1.attach(2);
 // attaches the servo on pin 2 to the servo object
 delay(15);
 myservo1.write(180);
 // sets the servo position according to the scaled value
 delay(5000);
 // waits 1000ms for it to get to the position
 myservo1.detach();
 delay(10000);
Â
Â
// Step Motor Code Move to Position 2Â
// WORK IN PROGRESS
// Code To Turn The Fluid One Dispenser
 myservo2.attach(3);
 // attaches the servo on pin 3 to the servo object
 delay(15);
 myservo2.write(180);
 // sets the servo position according to the scaled value
 delay(5000);
 // waits 5000ms for it to get to the position
 myservo2.detach();
 delay(10000);
 myservo2.attach(3);
 // attaches the servo on pin 3 to the servo object
 delay(15);
 myservo2.write(-90);
 // sets the servo position according to the scaled value
 delay(2000); // waits for it to get to the position
 myservo2.detach();
 delay(10000);
Â
// Step Motor Code Move to Position 3Â
// WORK IN PROGRESS
Â
 // Code To Turn The Fluid Two Dispenser
 myservo3.attach(5);
 // attaches the servo on pin 5 to the servo object
 delay(15);
 myservo3.write(180);
 // sets the servo position according to the scaled value
 delay(5000);
 // waits 1000ms for it to get to the position
 myservo3.detach();
 delay(10000);
 myservo3.attach(5);
 // attaches the servo on pin 5 to the servo object
 delay(15);
 myservo3.write(-90);
 // sets the servo position according to the scaled value
 delay(2000); // waits for it to get to the position
 myservo3.detach();
 delay(10000);
Â
// Step Motor Code Move to Back To Intial Position (0)Â
// WORK IN PROGRESS
}
I'm using a program where the stepper motor moves a cart with cup etc, etc, etc
So why do you want to attach() and detach() the stepper ?
Why do you keep attaching and detaching the servos ?
attach() them is setup() then leave them attached
So why do you want to attach() and detach() the stepper ?
I'm a beginner at coding for the Arduino
. I really do not know how the stepper operates while servos are implemented into the code and that's where I get confused. I want to know how to stop the stepper motor to position wait a certain amount of time then moves to next position.
Why do you keep attaching and detaching the servos ?
I keep attaching and detaching the servos because I don't want them to run all at the same time. I also have them in the void loop because I want to run the program multiple times.
Let's deal with the servos first.
attach() them in setup()
write() a value to them in setup() or loop() and they will stay in that position
Don't want them to move ? So don't write a different value to them
As to the stepper
Move it to a position and it will stay there
Don't want it to move ? So don't move it to a new position
For both the servos and stepper it would be convenient to put the movement code for them in a function. That way you can call it when required.
What actions/inputs should start the stepper and/or servo moves ?
Call the movement functions when the input signal is received and not each time through loop()
What order should they occur in ?