Controlling two steppers with one arduino

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!

Call pinMode on all your output pins, not just some of them.

AccelStepper will do this for you, show us the code you tried with
that library. You have to call run() method on each and every stepper
instance all the time with AccelStepper.

Hi!

Where should I call pinMode?
Should it be like this?

int dirPin = 2;
int stepperPin = 3;
void setup() {
 pinMode(dirPin, OUTPUT);
 pinMode(stepperPin, OUTPUT);
}
 void step(boolean dir,int steps){
 digitalWrite(dirPin,dir);
 digitalWrite(1, LOW); 
 digitalWrite(2, LOW); 
 digitalWrite(3, LOW); 
 digitalWrite(4, LOW); 
 digitalWrite(5, LOW); 
 digitalWrite(6, LOW); 
 digitalWrite(7, LOW); 
 digitalWrite(8, LOW); 
 digitalWrite(9, LOW); 
 digitalWrite(10, LOW); 
 digitalWrite(11, LOW); 
 digitalWrite(12, LOW); 
 digitalWrite(13, 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);
}

I used a simple example, that comes with the library

// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
/// \author  Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2009 Mike McCauley
// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup()
{  
   stepper.setMaxSpeed(1000);
   stepper.setSpeed(50);	
}

void loop()
{  
   stepper.runSpeed();
}

Thanks a lot! : )

A call to the pinMode function should be in the setup function.

Hi,
How are you powering the stepper motors.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

YOUR circuit please, not the fritzing one. And please do not use fritzy.

Tom.... :slight_smile:

Grumpy_Mike:
A call to the pinMode function should be in the setup function.

Perfect!

That solved my question!

Thanks