Go Down

### Topic: Obtain variable (degrees) of the movements of two stepper motors (Read 259 times)previous topic - next topic

#### mofalafel

##### Jun 05, 2019, 12:07 pm
Hi,

I ve this code with a movements for a scanner 3d with a LIDAR. My problem is that i need to know the degrees of the movements in every moment, for mix it with the LIDAR measures. How can i get these variables?

Quote
#include <Stepper.h>
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution for the motor
float alpha=0;
float alpha2=0;
const float pi = 3.141593;
int f=0;

Stepper myStepperZ(stepsPerRevolution, 8, 9, 10, 11);  // initialize the stepper library on pins 8 through 11:
Stepper myStepperY(stepsPerRevolution, 3, 4, 5, 6);

void setup() {
myStepperZ.setSpeed(20); // set the speed at 20 rpm:
myStepperY.setSpeed(5); // set the speed at 5 rpm:
Serial.begin(9600); // initialize the serial port:
}

void loop() {
delay(6000);  //delay de un minuto antes de empezar
myStepperZ.step(200);// step one revolution  in one direction (sentido horario):
delay(500);
myStepperY.step(1);
delay(500);
myStepperZ.step(-200);// step one revolution in the other direction (sentido antihorario):
delay(500);
myStepperY.step(1);
delay(500);
}
}

#### Robin2

#1
##### Jun 05, 2019, 12:32 pmLast Edit: Jun 05, 2019, 12:33 pm by Robin2
This code has several stepper movements and lots of delay()s and a WHILE
Code: [Select]
`void loop() {    delay(6000);  //delay de un minuto antes de empezar    while(contador<25){  //25repeticiones        myStepperZ.step(200);// step one revolution  in one direction (sentido horario):        delay(500);        myStepperY.step(1);        delay(500);        myStepperZ.step(-200);// step one revolution in the other direction (sentido antihorario):        delay(500);        myStepperY.step(1);        delay(500);        contador++;    }}`

At what points in the program do you wish to identify the angle of the stepper motor?

Code such as
Code: [Select]
`myStepperZ.step(200);`
will block the Arduino until all 200 steps are complete. If you need to know the angles during that move you need EITHER to move in single steps OR use the non-blocking ability of the AccelStepper library

What stepper motor driver are you using?

...R
Stepper Motor Basics
Simple Stepper Code
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up