Adafruit #570 in Inc 5000 & #11 in manufacturing - fastest-growing private companies in America - INC 5000 - Read more!

Adafruit Motorshield V2 instantiating

by Techniker2013 on Mon Oct 28, 2013 8:30 am

Hi everyone,

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 | TOGGLE FULL SIZE
#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();
}
Techniker2013
 
Posts: 2
Joined: Mon Oct 28, 2013 7:45 am
Location: Germany

Re: Adafruit Motorshield V2 instantiating

by adafruit_support_bill on Mon Oct 28, 2013 9:15 am

AF_Motor is the library for the older motor shield. For the V2 shield you need the V2 library.
https://github.com/adafruit/Adafruit_Mo ... V2_Library

Also, make sure you are using the Adafruit-modified version of AccelStepper.
https://github.com/adafruit/AccelStepper
User avatar
adafruit_support_bill
 
Posts: 28826
Joined: Sat Feb 07, 2009 9:11 am

Re: Adafruit Motorshield V2 instantiating

by Techniker2013 on Wed Oct 30, 2013 4:26 am

Thank you for the help, i used the wrong library like you said.
Could you send me a link for the modified version of the Accelstepper reference, or does it have the same programming commands, like the common one?

Yours sincerely, Techniker2013
Techniker2013
 
Posts: 2
Joined: Mon Oct 28, 2013 7:45 am
Location: Germany

Re: Adafruit Motorshield V2 instantiating

by adafruit_support_bill on Wed Oct 30, 2013 5:34 am

It may be a few revs behind the current release, but the API should be basically the same. The .h file is the ultimate reference.
User avatar
adafruit_support_bill
 
Posts: 28826
Joined: Sat Feb 07, 2009 9:11 am