Pages: [1]   Go Down
Author Topic: Stepper motors turn less then value shown on serial monitor  (Read 514 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys any help is welcome

I am trying to move two tables to make circle something like  g2 code in cnc programing
It seems to me all calculations is done correctly the numbers printed on serial monitor is right but stepper motors move 100 steps only.

here is the code
#include <AccelStepper.h>
#include <AFMotor.h>
float axis_x = 50 ;
float radius = 50 ;
float axis_y = 0  ;
float steps = 200 ;   //if pich of the screw is 5mm and stepper motor is 180 steps per revolution 36 steps is 1mm
float point_e  ;
float point_f = 0.5 * 200 ;
int var ;
// two stepper motors one on each port
AF_Stepper motor1(200, 1);
AF_Stepper motor2(200, 2);

// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
// wrappers for the first motor!
void forwardstep1() { 
  motor1.onestep(FORWARD, SINGLE);
void backwardstep1() { 
  motor1.onestep(BACKWARD, SINGLE);
// wrappers for the second motor!
void forwardstep2() { 
  motor2.onestep(FORWARD, SINGLE);
void backwardstep2() { 
  motor2.onestep(BACKWARD, SINGLE);

// Motor shield has two motor ports, now we'll wrap them in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);

void setup()


void loop()
   while(var < 100 ){                                   // axis y moves 0.5 milimetere every loop 100 times
    axis_y = axis_y + 0.5 ; 
     Serial.println (var) ;
     Serial.println  (point_f , 2) ;                       //print out to serial monitor  axis y
    float side_a = axis_x ;                            //side_a takes value from axis_x
    axis_x = sqrt(sq(radius) - sq(axis_y)) ;          //calculate axis_x value       
      point_e =  (side_a - axis_x) * steps ;        //calculate point_e = difference from privius axis_x  and current axis_x
      Serial.println  (point_e, 2) ;                //print out to serial monitor point_e  value multiplied by number of steps divided by pitch of the screw
        stepper1.moveTo(point_f);   //stepper1 motor should turn 100 steps every loop, but it doesn't motor turns half turn         
        stepper2.moveTo(point_e);   //stepper2 motor should move point_e value, which is 0.5 steps and increase every loop up to 1410.67 steps
  ;         // but it doesn't,  motor turns half turn

Manchester (England England)
Offline Offline
Brattain Member
Karma: 625
Posts: 34112
Solder is electric glue
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Normally this happens when you are trying to go too fast. Drop the speed by half and see if it still happens.

Pages: [1]   Go Up
Jump to: