Hello
Beginner Programming ; I'm looking for be able to control the number of turns that make a stepper motor.
For this I have a card auduino uno arduino and a platinum motor shield Rev3 ; and a bipolar stepper motor of 48 steps ans 4 threads.
I try to do it but I've a lack information about the control of the card so if you can guide me or give me a similar program so that I can finally reach my goal I will be very grateful.
Thank you in advance ![]()
Ps : sorry for the falts i don't speak english very vell
Have you looked at the Stepper and AccelStepper libraries and their examples?
Yes but I don't understand how it works I come doing turn thé motor but I can't stop it ...
You need to explain more clearly what it is that you don't understand.
It sounds like you have the motor correctly connected to the motor driver board and that you have a sketch that sends suitable pulses to make the motor move.
Explain what you don't understand and post a copy of your sketch (use code tags please - the # icon) and we may be able to help.
...R
I did this program and I'm wondering how to get to stop the motor in a number of steps precise and what they have to put pins in the object stepper (Pwm? braking?)
I know il must be ridiculous for you but can you help me ?
#include <Stepper.h>
Stepper motor(48, , , , );
void setup()
{
motor.setSpeed(1);
}
void loop()
{
motor.step(15);
delay(200);
}
Your code is short - which is great.
The reason it keeps moving is because the function loop() runs over and over again for ever.
If you just want the stepper to move a certain number of steps then your code must control the number of steps. There are many ways to do that. This is one way. It should do 48 steps and then stop. You will need to reset the Arduino to get it to do another 48 steps
#include <Stepper.h>
boolean allDone = false;
int numSteps = 48;
 Â
Stepper motor(48, , , , );
void setup()
{
motor.setSpeed(1);
}
void loop()
{
  if (allDone == false) {
   for (int n = 0; n < numSteps; n++) {
     motor.step(15);
     delay(200);
   }
   allDone = true;
  }
}
And see what it looks like when you use code tags - as I requested.
...R
I tested your program but when I activate the stepper take a step forward and one step backward
What can be the problem? power or connection?
That was your program, not mine.
Did you try making the changes I suggested?
...R
yes but I suceed to do the program it give this and it work
#include <Stepper.h>
boolean allDone = false;
const int Nbdepas = 48;
Stepper myStepper(Nbdepas, 12 , 13);
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;
const int bouton = 2;
int x = 0;
void setup() {
Serial.begin(9600);
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB,HIGH);
digitalWrite(brakeA,LOW);
digitalWrite(brakeB, LOW);
pinMode(bouton, INPUT);
Serial.begin(9600);
myStepper.setSpeed(15);
}
void loop()
{
if (allDone == false) {
int test = digitalRead(bouton);
if (test == HIGH) {
myStepper.step(48);
delay(200);
allDone = true;
}
}
}
23Bastien:
yes but I suceed to do the program it give this and it work
I'm not sure what that means, but I'm glad it works.
...R