Hi I'm new to arduino and c programming I'd like to start a project with a stepper motor and a spark fun easy driver, I've done a few tutorials and have some examples of accellstepper library codes.
As I have little experience I am finding it difficult to make my motor behave the way I want.
I'm looking to drive the stepper in a clock wise direction when I hold button a and the drive counter clockwise when I hold button b.
Is their any tutorials that explain how I can achieve this. I have a list of commands from the accellstepper website but I cannot find how to use them.
From what I can see that driver board just needs step and direction signals from the Arduino.
Set direction High or Low depending on the direction you want.
Make a code loop that repeats N times and which contains
set step HIGH
wait for 800msecs
set step LOW
wait for 800msecs
It should move the motor through N steps. 800msecs works with the stepper motors I have. I need to increase the voltage to the motors to get them to go significantly faster. You could try different values.
I'm not sure how to add that to my code this is what I've scrapped up so far from a bunch of tutorials.
#include <AccelStepper.h>
AccelStepper stepper(1,3,2); //1 means a stepper driver (with Step and Direction pins) step pin = 3 dir pin = 2
int forward = 7; //pin number for the up button
int backward = 8; //pin number for the down button
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
stepper.setMaxSpeed(500);
stepper.setSpeed(500);
pinMode(forward, INPUT);
pinMode(backward, INPUT);
}
void loop() {
Serial.println(digitalRead(forward)); // Read the pin and display the value
Serial.println(digitalRead(backward)); // Read the pin and display the value
if (digitalRead(forward) == HIGH) { // check if the input is HIGH (button pushed)
stepper.move(+10);
stepper.run();
}
if (digitalRead(backward) == HIGH) { // check if the input is HIGH (button pushed)
stepper.move(-10);
stepper.run();
}
}
With this I have 2 problems that I know of, first the direction doesn't change when I use the backwards button. Secondly the stepper runs for longer then me holding the button.
Using the serial screen I see that the input for both forward and backward stay high after pressing them for about 3-5 seconds, I assume this is why the stepper runs on when I release the button
I'm wanting it to only move while I hold the button down.
I could just use dc motors for this but as my design is for a robotic arm, once I have it built and moving I want to automate it with so I think steppers would be best for this.