Hi there,
For our school project, we’re trying to program 3 stepper motors (NEMA17 0.9 degrees type: 42BYGHM809) with Arduino. To manage the stepper motors, we use Easydrivers 4.4.
The motors will be integrated into a home build linear actuator with the use of lead-screw (see picture below).
We’re trying to create a loop (kind of a scene), in which all of the 3 motors are powered at the same time. For example, motor 1 will first rotate 200 rounds, stop and then turn 100 rounds in the opposite direction. At the same time, motor 2 will rotate 100 rounds and then 50 backwards. Motor 3 waits for motors 1 and 2 to finish and then will rotate 300 rounds.
We have searched the internet for several codes to get the motors rotating. However, we’re not clear on which code the best option is to adjust the speed, number of rotations, delays, et cetera. The code we have written right now is the following:
int dirpin1 = 6;
int steppin1 = 7;
int dirpin2 = 4;
int steppin2 = 5;
int dirpin3 = 2;
int steppin3 = 3;
int rounds = 3200;
void setup()
{
pinMode(dirpin1, OUTPUT);
pinMode(steppin2, OUTPUT);
pinMode(dirpin2, OUTPUT);
pinMode(steppin2, OUTPUT);
pinMode(dirpin3, OUTPUT);
pinMode(steppin3, OUTPUT);
}
void loop()
{
// change direction
int i;
digitalWrite(dirpin1, HIGH);
digitalWrite(dirpin2, HIGH);
digitalWrite(dirpin3, HIGH);
// Motor 1: make 6 rounds
for (i = 0; i < (rounds*6); i++) {
digitalWrite(steppin1, HIGH);
digitalWrite(steppin1, LOW);
delayMicroseconds(90);
}
// Motor 2: make 3 rounds
for (i = 0; i < (rounds*3); i++) {
digitalWrite(steppin2, HIGH);
digitalWrite(steppin2, LOW);
delayMicroseconds(210);
}
// Motor 3: make 1 round
for (i = 0; i < (rounds*1); i++) {
digitalWrite(steppin3, HIGH);
digitalWrite(steppin3, LOW);
delayMicroseconds(260);
}
// change direction
digitalWrite(dirpin1, LOW);
digitalWrite(dirpin2, LOW);
digitalWrite(dirpin3, LOW);
// Motor 1: make 6 rounds
for (i = 0; i < (rounds*6); i++) {
digitalWrite(steppin1, LOW);
digitalWrite(steppin1, HIGH);
delayMicroseconds(90);
}
// motor 2: make 3 rounds
for (i = 0; i < (rounds*3); i++) {
digitalWrite(steppin2, LOW);
digitalWrite(steppin2, HIGH);
delayMicroseconds(210);
}
// motor 3: make 1 round
for (i = 0; i < (rounds*1); i++) {
digitalWrite(steppin3, LOW);
digitalWrite(steppin3, HIGH);
delayMicroseconds(260);
}
}
It would be great if you could have a thorough look at the code and also point us into the right direction concerning the right codes to make the adjustments.
Many thanks.
Kind regards