I'm having difficulty using the Accel stepper library. Using plain code I can get my motor spinning just fine so I know it's hooked up right. I just can't get Accel lub to work for me! I've tried the examples and I don't even get a humm.
Here is the example I'm using (slightly modified).
#include <AccelStepper.h>
AccelStepper stepper1(1, 2, 3); // Define stepper and the pins we will use
void setup()
{
int enPin = 4; // Enable Pin
pinMode(enPin, OUTPUT); // set enable pin to output
digitalWrite(enPin, HIGH); // turn on enable
stepper1.setMaxSpeed(11000.0); // set speed
stepper1.setAcceleration(10000.0); // set accel
stepper1.moveTo(6000); // set position
stepper1.enableOutputs();
}
void loop()
{
// Change direction at the limits
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
stepper1.run();
}
And here is the working plain code.
// Set up the Pins
int dirPin = 2;
int stepperPin = 3;
int enPin = 4;
int ledPin = 9;
Is it possible that the Enable pin is Active-LOW? I notice that in the code that works you never actually write to the enPin.
I tried the enPin low as well still doesn't work, but now the motor humms and the rotor is locked! I'm sure it's something obvious, you know starring me in the face kind of thing. I just cannot figure it out!
Remember that starring me in the face comment? Well I rechecked the code, and I forgot to save changes made when I swapped the step & dir pins..... DOH! Now with the pins swapped and the enable set for active low, taaadaaa!
Thanks a bunch for your help John, but I can't help thinking I should been able to figure this one out! I guess I had a case of temporary dumb azzz!
Thanks again
Submicro
P.S. Shouldn't I be able to set enable with the library? There are no examples of it!
Here is the modified code that works, but I've commented out a few lines that I shouldn't need if I can figure out how to use this library properly. If I uncomment those lines then the code works.
#include <AccelStepper.h>
AccelStepper stepper1(1, 3, 2); // Define stepper and the pins we will use
void setup()
{
//int enPin = 4; // Enable Pin
//pinMode(enPin, OUTPUT); // set enable pin to output
//digitalWrite(enPin, LOW); // turn on enable
stepper1.setMaxSpeed(20000.0); // set speed
stepper1.setAcceleration(10000.0); // set accel
stepper1.moveTo(600); // set position
stepper1.setEnablePin(4);
stepper1.enableOutputs();
}
void loop()
{
// Change direction at the limits
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
stepper1.run();
}
I see I was trying to do just the ensble pin. So even if I'm not inverting the other pins, I have to include them in the function call.
I'llgive that a try. I guess I'm getting the syntax wrong because it's not working.
SubMicro:
I see I was trying to do just the ensble pin. So even if I'm not inverting the other pins, I have to include them in the function call.
I'llgive that a try. I guess I'm getting the syntax wrong because it's not working.
Hello I went to the Accellstepper google group and they gave me an example of how to use the function. Now I'm good to go
It was what you showed me but 4 some reason it didn't work, but this time it did.
In case your interested here is the working test code.
#include <AccelStepper.h>
AccelStepper stepper1(1, 3, 2); // Define stepper and the pins we will use
void setup()
{
stepper1.setMaxSpeed(20000.0); // set speed
stepper1.setAcceleration(10000.0); // set accel
stepper1.moveTo(1160000); // set position
stepper1.setEnablePin(4);
stepper1.setPinsInverted(false, false, true);
stepper1.enableOutputs();
}
void loop()
{
// Change direction at the limits
if (stepper1.distanceToGo() == 0)
stepper1.moveTo(-stepper1.currentPosition());
stepper1.run();
}
Good evening, Brazilian greetings, I'm starting on arduino and I learned a lot by reading these posts I would like, and I'm studying the stepper compartments using a register library, I need the engine to turn
clockwise to be able to give an example in the programming please