Cnc Plotter with Adafruit Motorshield V2

Hi there!
I've got the following problem and hopefully, somebody of you guys could help me out. :slight_smile:

I'm working on a CNC Plotter machine. I'm using the Arduino Uno and two Adafruit Motorshields V2. For the motors, i'm using the normal adafruit steppers with 200 steps.

Everything allright and i've got no problem with the mechanics or how to run the steppers.

My Question is about the code: How is it possible to run the two steppers at the same time. I've googled a lot but i didn't find something helpful to me.:confused: It's no problem for me to run one stepper, but i'm not getting how to run two at the same time. I tried it also with the accel stepper library. It worked, but the steppers were rotating only one step. Thats not very helpful for my project...

Is there maybe a way to run the steppers with the accel stepper library, more than one step at the same time? Or is it even possible to use a CNC Plotter software with the Adafruit shield? So that i can draw, what i would like to Plot, if you know what i mean...

Hopefully anybody could help me out, i would be very very grateful for that. Thanks for your time guys!:slight_smile:

The motorshields are not a good choice for controlling stepper motors and may limit the performance you caan get. Have a look at Stepper Motor Basics

I don't understand why you have doubts about the ability to control 2 stepper motors? It should be just as easy as running 1 motor.

If you use the AccelStepper library you can create two instances, say myStepperA and myStepperB and run them both with

myStepperA.run();
myStepperB.run();

The AccelStepper library is not intended for the co-ordinated movement of two motors - for example where one is expected to do 112 steps in the time the other should do 401 steps.

I believe the MultiStepper library (from the same source) can do that but I have no experience of it. I have written my own code to control 3 motors on a small lathe - very similar to this Simple Stepper Code.

...R

Thanks very much for your answer!

Could you maybe send me the code of what you mean? Because i dont get it 100%... :confused:

That would be very Kind:)

CaptainAmerica24:
Could you maybe send me the code of what you mean? Because i dont get it 100%... :confused:

Did you study the code I gave a link to?

I don't understand what you don't understand. If you explain I will try to help.

...R

#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
#include <Servo.h>

Adafruit_MotorShield AFMSbot(0x61); 
Adafruit_MotorShield AFMStop(0x60); 

Adafruit_StepperMotor *myStepper1 = AFMSbot.getStepper(200, 1);
Adafruit_StepperMotor *myStepper2 = AFMSbot.getStepper(200, 2);

void step1() {  
  myStepper1->step(400, FORWARD, DOUBLE);
}
void step12() {  
  myStepper1->step(400, BACKWARD, DOUBLE);
}
void step2() {  
  myStepper2->step(400, FORWARD, DOUBLE);
}
void step22() {  
  myStepper2->step(400, BACKWARD, DOUBLE);
}

AccelStepper stepper1(step1, step12);
AccelStepper stepper2(step2, step22);


Servo myServo;
int angle = 0;


void setup(){
   AFMSbot.begin();
   AFMStop.begin();
   
  stepper1.setMaxSpeed(100.0);
  stepper1.setAcceleration(100.0);
  stepper1.moveTo(100000);
    
  stepper2.setMaxSpeed(200.0);
  stepper2.setAcceleration(100.0);
  stepper2.moveTo(50000);
   
   myServo.attach(10);
}


void loop(){

    if (stepper1.distanceToGo() == 0)
  stepper1.moveTo(-stepper1.currentPosition());

    if (stepper2.distanceToGo() == 0)
  stepper2.moveTo(-stepper2.currentPosition());


    stepper1.run();
    stepper2.run();


   for(angle=0; angle < 180; angle += 1) {               
      myServo.write(angle);               
      delay(5);         
   }                
   for(angle=180; angle >= 1; angle -= 1){
      myServo.write(angle);
      delay(5); 
   }
}

Im using this code, but the Steppers are only rotating 1 STEP! :confused:
I would like to know, how i have to change the code to get the Steppers rotating f.e. 200 steps
I think your code is good for your Motor Board but i dont think it works with my board…

(Im using also a servo...)
But the code parts for the servo are working...

I know, that im using the method "onestep", but the code is not working with another method...

I would like to help but the truth is I have no idea what those Adafruit libraries do. They seem to me to make simple things complex.

...R

Thanks anyway bro:)