ChristopheDV:
I did some tests with the Custom Stepper Library and it worked.
At startup my motor turns 90 degrees to left and then 90 degrees to the right, which is correct according to the code.
What I want, is when I push button1 the motor turns 90 degrees to the left and when I press button2 , 90 degrees to the right.
Hi
there is already a similar question put to you but I cant find your response.
My question is how can your code be used with a stepper driver which requires just 2 pins - 1) direction & 2) pulse.
Your response would be much appreciated as I have almost zero arduino experience & have just begun on that long road of learning.............
Many thanks
Mike
Hi,
I am making laser scanning device for which I need precise small coordinate , for this I need to drive stepper motor very slow. Can anybody tell me how to have RPM less than 1 RPM?
jehanzaib:
Hi,
I am making laser scanning device for which I need precise small coordinate , for this I need to drive stepper motor very slow. Can anybody tell me how to have RPM less than 1 RPM?
Did you look at the code I linked to in the previous Reply #22
You can modify it to do 1 revolution per month if you want to.
I have a problem interfacing my motor driver to the motor to arduino. We know that 4 motor pins are to assigned in the arduino, but how if my 4 motor pins are connected to the driver. I can't assign pin numbers to the arduino since it is connected to the driver.
Rbtimbre:
I have a problem interfacing my motor driver to the motor to arduino. We know that 4 motor pins are to assigned in the arduino, but how if my 4 motor pins are connected to the driver. I can't assign pin numbers to the arduino since it is connected to the driver.
You will have to provide a link to the datasheet for your motor driver before you can get an answer.
Rbtimbre:
I have a problem interfacing my motor driver to the motor to arduino. We know that 4 motor pins are to assigned in the arduino, but how if my 4 motor pins are connected to the driver. I can't assign pin numbers to the arduino since it is connected to the driver.
You have to assign the pins on Arduino what you are using to drive the driver. Its the drivers job then handle the motor.
I have managed to get the stepper motor to work with a push button, here is my code, if it's of any help.
#include <CustomStepper.h>
CustomStepper stepper(4, 5, 6, 7);
int buttonPin = 8, // start button
buttonState = 0, // for holding state of button
stateMachine = 0, // to transition between different states fo
start = 0; // to start the state machine
void setup() {
pinMode(buttonPin, INPUT);
stepper.setRPM(15);
stepper.setSPR(4075.7728395);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH)
{
start = 1;
}
while(start == 1)
{
if (stepper.isDone() && stateMachine == 0) // state one, 180deg clockwise
{
stepper.setDirection(CW);
stepper.rotateDegrees(180.0);
stateMachine = 1;
}
if (stepper.isDone() && stateMachine == 1) // state two, 90deg counter clockwise
{
stepper.setDirection(CCW);
stepper.rotateDegrees(90.0);
stateMachine = 2;
}
if (stepper.isDone() && stateMachine == 2) //state three, 360deg clockwise
{
stepper.setDirection(CW);
stepper.rotateDegrees(360.0);
stateMachine = 3;
}
if (stepper.isDone() && stateMachine == 3) // state four, 90deg counter clockwise to finish
{ // in the position were we left off.
stepper.setDirection(CCW);
stepper.rotateDegrees(90.0);
stateMachine = 4;
}
if(stepper.isDone() && stateMachine == 4) // and finaly, state five (reset state variables)
{
stateMachine = 0;
start = 0;
}
stepper.run();
}
}
This code will turn the stepper motor 180deg clockwise, 90deg counter clockwise, 360deg clockwise and lastly 90deg counter clockwise to finish up were we started from. The board I used is the Uno, this code should work with the Mega 2560.
I agree that none of this works as soon as you try using a serial connect. Is there any way around this? I'd like to be able to show the stepper motor angle on the serial monitor and then type in a new angle. So simple but can't be done with this library. Or can it?
Is there bug?
void CustomStepper::run()
{
if (this->timer <= micros() && micros() < this->timer + this->time)
this->step();
}
Did I understand this right? when you call run() it will check that if time is more than timer and step. But it also check that time is not more than timer + step delay. So if run is called slower that delay it will get stuck for ever? Also when micros get reseted (each 70 minutes) this will stuck for ever?
I think
if (this->timer <= micros() || this->timer > micros() + this->time)
this->step();
Will do better job.
First part will do step each time when timer expires. Second part will do tick if micros do overflow and at same time run is too late.
It is not perfect neither because it will do one step too early at each 70minutes when micros overflow. But at least it does not get stuck.
Actually looks that this whole logic with CONTINUOUS mode is so rotten that I must ask that did you test it at all?
Fixed step method below. I only check use scenarios what I use. At this point I have found 3 different bug from that library so I assume that this is still broken but at least it works now for me
I have been using this code too, and it works well.
Just one issue when the required rotations or degrees is completed the code seems to return all the i/o to low state and releases the motor allowing it to freewheel, esp if it was going quick to start with.
How do I get the class to hold the motor at zero speed, I did try direction = stop, and speed = 0, neither worked, is it something to do with this continuous mode I just saw further up.