MobaTools Stepper Help

Hey guys im new to this so i cant figure this out
Im trying to make the stepper motor go clockwise and then counter clockwise
So if you think about it like a clock i want it to go clockwise until it hits the 9 and then back counter clockwise until it hits the 3 continuously.
-----12--
9 --------3--
------6------

#include <MobaTools.h>

const int stepsPerRevolution = 300;  // change this to fit the number of steps per revolution
//const int rolePerMinute = 15;         // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
const byte stPn[] = {2,3,4,5}; //pins used

MoToStepper myStepper(stepsPerRevolution, STEPDIR);

void setup() {
  myStepper.attach(stPn[0],stPn[1],stPn[2],stPn[3]);
  myStepper.setSpeed(240);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {  
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.rotate(1);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.rotate(-1);
  delay(500);
}

Okay, so far so good. And what's the problem?
Did you get an error while compiling? Did you check the wiring?

how do i change the distance it travels before switching rotations. Right now it rapidly switches back and forth

You are using the "drive-the-motor-endlessly" function.

Steppermotors are made for just move an exact number of steps.

There are functions that make the stepper-motor run a defined number of steps.
How many steps result in a 180 degree turn depends on

  • the steppermotor you are using i.e. how many full-steps are one revolution
    usually this is 200 steps per revolution

  • your stepperdriver mode fullstep, halfstep, quarterstep etc.

You are working on an informatic project and what is needed most in an informatic project is information

post a datasheet of your stepper-motor or at least a link where you bought it or a picture with the type-number on it

post the datasheet of the stepper-driver you are using
If the stepper-driver has full/half/microstep options post a picture of how you have setup the wires/switches that define the stepmode

Did you download the documentation of the MobaTools?
there you have functions that use a number that represents degrees how much they should rotate.

best regards Stefan

Using a 28BYJ-48 Stepper motor with ULN2003 Driver
Here's a picture of it.

The tutorial names how many steps this steppermotor has per revolution.

doesn't matter what number i change "const int stepsPerRevolution = 300;" to as it doesn't work

You are using the wrong function

myStepper.rotate(1);

rotate(1) and rotate(-1) does "rotate-stepper-motor-for-ever"

You have to use a different function.
So my question is: do you have the documentation of the MobaTools?

to say it explicitly: I will not serve you ready to use code.
I will teach you how to effectively learning to code

First step to this is having the documentation

best regards Stefan

ok so instead of rotate what function moves it once?

do you have the documentation? answer with "yes" or "no"

oh ya sorry all the example code comments were in german

each and every library included the MobaTools-library has a documentation.
And inside this documentation all functions are described what they do and how you use them. So you simply read the documentation

The documentation is an extra PDF-file
There is an english version of the documentation

ya i already tried almost every function and its always the same outcome.
I replaced rotate with write(360) and got the same outcome
Im on this forums bc i hav been trying at this for hours, im a beginner
Thanks for the help

Go on the website that you have mentioned

and search for

steps per revolution

This will give you the right number for

const int stepsPerRevolution =  

if you google for "MobaTools documentation"

https://www.google.de/search?as_q=MobaTools+documentation

you will find the file MobaTools-241-en.pdf which is the english documentation.

You want the motor to turn an angle of 180 degrees.

Inside this PDF-file search for the word "angle"
until you find that section of the documentation that is about stepper-motors.
The MobaTools have more than just stepper-motors.

best regards Stefan

You cant search for a word in a PDF, but the word angle is in the write function which i said. The documentation says there is 32 steps per revolution but its says the steps per revolution is actually 2037 which i tried both numbers and same result. Right now it rotates back and forth rapidly

#include <MobaTools.h>

const int stepsPerRevolution = 32;  // change this to fit the number of steps per revolution
//const int rolePerMinute = 15;         // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
const byte stPn[] = {2,3,4,5};

// initialize the stepper library on pins 8 through 11:
MoToStepper myStepper(stepsPerRevolution, STEPDIR);

void setup() {
  myStepper.attach(stPn[0],stPn[1],stPn[2],stPn[3]);
  myStepper.setSpeed(240);
  //myStepper.setRampLen( 50 ); 
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {  
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.write(180); 
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.write(-180);
  delay(500);
}

Are you a low-level troll?

it works both:
searching for keywords with google inside of PDFs
and searching for words inside a PDF works too.

is a way too unprecise description of what is happening.
I'm very sorry I dropped my glas-sphere and it exploded to thousands of pieces
so I'm unable to see your stepper-motor moving through the glas-sphere.

There is no way around it to describe it in words or to upload a video of it to youtube.

If you read some more in the documentation you will find another function that makes the stepper-motor run a number of steps.
give it a value and watch how much your steppermotor turns

If you want to have a different behaviour of the stepper-motor you have to describe this behaviour.

There are some problems in your code:

The 28BYJ-48 Stepper has 2048 steps per revolution ( in full step mode ) because there is a reduction gear inside.

You don't use a step/dir driver ( such as a A4988 ) but the ULN2003 with an unipolar stepper. That's quite different.

And be aware that the stepper methods of MobaTools are not blocking. A delay of 500ms ist to small to reach the position.

So your sketch should look like:

#include <MobaTools.h>

const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution
//const int rolePerMinute = 15;         // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
const byte stPn[] = {2,3,4,5};

// initialize the stepper library on pins 8 through 11:
MoToStepper myStepper(stepsPerRevolution, FULLSTEP);

void setup() {
  myStepper.attach(stPn[0],stPn[1],stPn[2],stPn[3]);
  myStepper.setSpeed(150);      // 240 (=24 rev/min) is too fast for this stepper!
  myStepper.setRampLen( 500 ); 
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {  
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.write(180);         // go to 180° from starting position
  while ( myStepper.moving() ); // wait until stepper has reached 180°
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.write(-180);         // go to -180° from starting position
  while ( myStepper.moving() ); // wait until stepper has reached -180°
  delay(500);
}

Not all the examples :wink: . And I will add more examples with english comments in further versions :slightly_smiling_face:

omg thank you, switching stepdir to fullstep did the trick!