for my projekt at the technikal college I need to work with arduino and I have some troubles with it. I want to use the following componets to drive 2 stepper motors:
Arduino Uno
Adafruit Motorshield V2
2x pd2-013-42 bipolar stepper motors
I found an example for using 2 stepper motors and I tried to use it for my projekt, but sadly it didn´t worked as I thought it would.
The sketch I used is the AFMotor_MultiStepper with Accelstepper and AFMotor library, if I understand it right, it should make an objekt that the AccelStepper can use.
My problem at the moment is, that I don´t know if my code is wrong or if something else doesn´t work as I intended it would.
So far i could run it with the normal Stepper library to let it turn clock- and counterclockwhise, but I couldn´t figure out why it doesn´t work with this sketch.
The motor doesn´t take much current only about 0.05 A but it should take about 0.6 A, so no motorcoil is powered.
I´m new to Arduino and any kind of help would be appritiated.
Here is the code I used:
Code: Select all
#include <AccelStepper.h>
#include <AFMotor.h>
// Objekt mit (200 Schritten, an Port 1) z.B.
AF_Stepper motor1(200, 1);
AF_Stepper motor2(200, 2);
// SINGLE (eine Spule), DOUBLE (zwei Spulen), INTERLEAVE (wechsel zwischen SINGEL u. DOUBLE)
//für doppelte Auflösung aber halbe Geschwindigkeit, MICROSTEP (mit PWM (Pulsweitenmodulation) für ruhige Bewegung des Motors)
// Methoden für Vorwärts und Rückwärtsbewegung der Motoren
void forwardstep1() {
motor1.onestep(FORWARD, DOUBLE);
}
void backwardstep1() {
motor1.onestep(BACKWARD, DOUBLE);
}
void forwardstep2() {
motor2.onestep(FORWARD, DOUBLE);
}
void backwardstep2() {
motor2.onestep(BACKWARD, DOUBLE);
}
// Motor Ports nutzbar für Accelstepper machen
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);
void setup()
{
stepper1.setMaxSpeed(20.0);
stepper1.setAcceleration(10.0);
}
void loop()
{
stepper1.run();
}