I am an artist and try to finish my installation. (see pic) Therefore I need two steppers, which have to run simultaneously. As well I need to change the speed and the direction individually in the programming list, it should be kind of a composition, which I could change in detail.
Now, I got the latest Adafruit Motor Shild and the Itead Dual Motor Shild. The Itead shild can operate with more voltage, which also means that I can speed up the motor even more, right? So I still do not know, which shild I should take, because even I connect the 12V Adapter the full speed of the motors is quite slow, how can I improve?
The programming is as well a problem regarding the shilds and the circumstance, where I need to "wrap the steppers into an accel stepper-object". The example code from arduino is a mix of the library of adafruit and accel stepper. Isnt it possible just to control the two steppers with the adafruit library? Btw: Is there any proper manual for both library? I mean like a manual, which explains the structure of the code with examples?(Accel Stepper documentation is only about the functions)
Following you will see the code I am using right now:
Code: Select all
#include <AccelStepper.h>
#include <MultiStepper.h>
// Define the stepper motor and the pins that is connected to
AccelStepper stepper1(1, 2, 3); // (Typeof driver: with 2 pins, STEP, DIR)
AccelStepper stepper2(1, 6, 7);
MultiStepper steppersControl; // Create instance of MultiStepper
long gotoposition[2]; // An array to store the target positions for each stepper motor
void setup() {
stepper1.setMaxSpeed(1000); // Set maximum speed value for the stepper
stepper2.setMaxSpeed(1000);
// Adding the 3 steppers to the steppersControl instance for multi stepper control
steppersControl.addStepper(stepper1);
steppersControl.addStepper(stepper2);
void loop() {
// Store the target positions in the "gotopostion" array
gotoposition[0] = 2000; // 800 steps - full rotation with quater-step resolution
gotoposition[1] = 2000;
steppersControl.moveTo(gotoposition); // Calculates the required speed for all motors
steppersControl.runSpeedToPosition(); // Blocks until all steppers are in position
delay(1000);
gotoposition[0] = 0;
gotoposition[1] = 0;
steppersControl.moveTo(gotoposition);
steppersControl.runSpeedToPosition();
delay(1000);
}
[b]Here I can change it more or less individually, but isnt there a way with more shorcuts? Because for every individual change of speed and direction I need to add 5 code lines, relatively 6 with the delay...[/b]
Why does it only works with stepper1.setmaxspeed and not with just setspeed?
Underneath you see a code for one stepper with a shild, which I used. This was very easy, couldnt it work for 2 steppers, who run simultaneously as easy as that? Btw: Which function exactly runs them simultaneously?
Are this code lines responsible for it?
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
if (stepper2.distanceToGo() == 0)
stepper2.moveTo(-stepper2.currentPosition());
/* Example sketch to control a stepper motor with Arduino Motor Shield Rev3, Arduino UNO and Stepper.h library. More info: https://www.makerguides.com */
// Include the Stepper library:
#include <Stepper.h>
// Define number of steps per revolution:
const int stepsPerRevolution = 200;
// Give the motor control pins names:
#define pwmA 3
#define pwmB 11
#define brakeA 9
#define brakeB 8
#define dirA 12
#define dirB 13
// Initialize the stepper library on the motor shield:
Stepper myStepper = Stepper(stepsPerRevolution, dirA, dirB);
void setup() {
// Set the PWM and brake pins so that the direction pins can be used to control the motor:
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);
// Set the motor speed (RPMs):
myStepper.setSpeed(150);
}
void loop() {
// Step one revolution in one direction:
//Step on revolution in the other direction:
myStepper.step(650);
delay(1000);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(50);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(50);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(50);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(500);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(50);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(50);
myStepper.step(150);
delay(500);
myStepper.step(-150);
delay(50);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(50);
myStepper.setSpeed(50);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(50);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(50);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(50);
myStepper.step(150);
delay(50);
myStepper.step(-150);
delay(500);
myStepper.setSpeed(150);
myStepper.step(400);
delay(500);
myStepper.step(-200);
delay(50);
myStepper.step(200);
delay(50);
myStepper.step(-200);
delay(50);
myStepper.step(200);
delay(50);
myStepper.step(-200);
delay(50);
myStepper.step(200);
delay(50);
myStepper.step(-200);
delay(50);
myStepper.step(200);
delay(50);
myStepper.step(-200);
delay(50);
myStepper.step(200);
delay(50);
myStepper.step(-200);
delay(50);
myStepper.step(200);
delay(50);
myStepper.step(-200);
delay(50);
myStepper.step(200);
delay(50);
myStepper.step(-200);
delay(50);
myStepper.step(-850);
delay(10000);
}
Thanks a lot for your feedback!