Hello all!
I've been trying for a while to control a stepper motor with an Arduino. Ok, it shouldn't be a problem, but IT IS!
My final goal is to control 8 stepper motors with an Arduino. The idea is to build a crazy machine that is supposed to make kites. The machine works like some kind of assembly line, so the motors will have to operate in a sequence, with different speeds (not so difficult to achieve) and it should work around 10 hours a day.
I've been doing this step by step, and the thing I'm here for is: to try to find out why when I ask one Stepper1 to move, Stepper2 follows the movement - not perfectly, and how to control the steppers independently
The system
Arduino UNO
A4988
Stepper Motor of 1.8 degrees/step
12V/5A power source
The wiring[\b]
I'm basically following the wiring described here: http://www.schmalzhaus.com/EasyDriver/Examples/611x704xExample4_bb.png.pagespeed.ic.A090jkNLqs.png
With the obvious difference that I'm using a A4988 driver. Also:
- Both A4988 VCC Inputs are connected to the Arduino 5V output
- Everything is (hopefully) grounded
The code
** **int dirPin = 2; int stepperPin = 3; void setup() { pinMode(dirPin, OUTPUT); pinMode(stepperPin, OUTPUT); } void step(boolean dir,int steps){ digitalWrite(dirPin,dir); digitalWrite(8, LOW); digitalWrite(9, LOW); delay(50); for(int i=0;i<steps;i++){ digitalWrite(stepperPin, HIGH); delayMicroseconds(3000); digitalWrite(stepperPin, LOW); delayMicroseconds(3000); } } void loop(){ step(false,1600); delay(500); step(true,1600); delay(500); }** **
Other Information
- I also tried using the AccelStepper library without success (the motors spin "jumping")
- I managed, with the code above, to control one stepper
The lines
** **digitalWrite(8, LOW); digitalWrite(9, LOW);** **
Are an attempt to keep the 8 and 9 pins at 0V
I also tried putting them inside the loop
** **for(int i=0;i<steps;i++){ digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(stepperPin, HIGH); delayMicroseconds(3000); digitalWrite(stepperPin, LOW); delayMicroseconds(3000); }** **
Thanks in advance!