Motor Shield and EasyDriver board combo

Hello there! I'm building a dual dc motor setup with an arduino, a motor shield and a second motor powered via an easydriver board. I've got two pieces of code that work absolutely fine when seperated. However when I try and combine both codes they seem to interfere and the laser motor runs very slowly. Is there any way I can put in two loops or some other way of seperating the two code parts? Any advice would be great! Both motors are bipolar stepper motors drawing 1750 mAh. The arduino is being powered by USB and the stage motor is connected directly to it. The second motor is connected to the easydriver board which is then connected to the arduino via pins 4 & 5. It is also grounded through the arduino. The easydriver has its own powersupply providing 9V at 2A. Once again both motors run fine when the code is seperated so either there is a problem with the power supply or the code? I've taken the code from online tutorials and edited it to suit my set up. Is it possible to run this in two seperate loops or are the delay functions causing an issue here?

int Distance = 0; //Records Steps
int delaylegnth = 30;

void setup() {
//LASER MOTOR DEFINITIONS
pinMode(5, OUTPUT); //DIRECTION
pinMode(4, OUTPUT); //STEP
digitalWrite(5, LOW); //sets to low voltage
digitalWrite(4, LOW); //sets to low voltage

//STAGE MOTOR DEFINITIONS
//establish motor direction toggle pins
pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???
pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???

//establish motor brake pins
pinMode(9, OUTPUT); //brake (disable) CH A
pinMode(8, OUTPUT); //brake (disable) CH B

}

void loop() {

//LASER MOTOR CODES
digitalWrite(4, LOW); //CHANGE TO LOW IN ORDER FOR MOTOR TO TURN
delay(10);
digitalWrite(4, HIGH);
delay(10);
Distance = Distance + 1; //records the step

// ensure end of move is completed

if (Distance == 10)

//move has been completed now continues in the same direction

if (digitalRead(5) == HIGH)
{
digitalWrite(5, LOW);
}
else
{
digitalWrite(5, HIGH);
}
//reset the distance to 0 as new move is carried out
//start a new move

//STAGE MOTOR CODES
digitalWrite(9, LOW); //ENABLE CH A
digitalWrite(8, HIGH); //DISABLE CH B

digitalWrite(12, HIGH); //Sets direction of CH A
analogWrite(3, 255); //Moves CH A

delay(10);

digitalWrite(9, HIGH); //DISABLE CH A
digitalWrite(8, LOW); //ENABLE CH B

digitalWrite(13, HIGH); //Sets direction of CH B
analogWrite(11, 255); //Moves CH B

delay(10);

digitalWrite(9, LOW); //ENABLE CH A
digitalWrite(8, HIGH); //DISABLE CH B

digitalWrite(12, LOW); //Sets direction of CH A
analogWrite(3, 255); //Moves CH A

delay(10);

digitalWrite(9, HIGH); //DISABLE CH A
digitalWrite(8, LOW); //ENABLE CH B

digitalWrite(13, LOW); //Sets direction of CH B
analogWrite(11, 255); //Moves CH B

delay(10);

}

First, please use the code button </> to make your code more readable - it should look like this

Second, an Easydriver can only provide 700mA so it would not be much use with an 1.75 amp motor. You should probably use a Pololu DRV8825.

Third, why not make life simple and use a DRV8825 for both motors.

Fourth, if you want the two motors to run at the same time you need to interleave the step pulses for the two motors.

Fifth, your code is not complete so I have no idea how the motors are connected to the Arduino.

Sixth, what power supply (volts and amps) are you using for the motors.

Seventh, your first line “I’m building a dual dc motor setup with an arduino” seems to be incorrect if you are using two stepper motors rather than two DC motors. (Successful programming requires the details to be precisely correct).

…R
Stepper Motor Basics

Hi Robin, thanks for getting back to me so soon! Sorry for the confusion in my post, I'm still quite new to this. Also I posted so really incorrect stuff there. The motors are 0.33A each not 1.75 so the easy driver works for them. I would use two easy drivers but with the shield added to the arduino I can power one motor from it and the second from a dedicated power source connected to the easydriver. It also makes the system far more efficient and tidier, this will make things a lot easier when I place it in a microscope. The motors are steppers not DC so that was way off the mark as well.

The main issue I'm having is how to interweave the step pulses. The delay functions are overriding each other and so the pulses aren't properly communicated. As a result I need to use the millis function with a timer as this will allow the system to run both simulataneously. Have you any recommendations on how to do this with a motor? I've tried finding some samples and even had a look at the accelstepper library but I'm still finding it difficult to grasp.

ben_mclarney:
The main issue I'm having is how to interweave the step pulses.

A simple way is to create two functions (one for each motor) which will cause the motor to move a single step - call then stepMotorA() and stepMotorB()

The content of these functions may need to be quite different so they work with the different drivers. The important thing is that, when called, the effect on the motor is identical.

Then you can write your code to make the motors move together or separately as required. A very crude example would be like this

void loop() {
    curMillis = millis();
    if (curMillis - lastMoveMotorAMillis >= motorAstepInterval) {
            lastMoveMotorAMillis += motorAstepInterval;
            stepMotorA();
    }
    if (curMillis - lastMoveMotorBMillis >= motorBstepInterval) {
            lastMoveMotorBMillis += motorBstepInterval;
            stepMotorB();
    }
}

...R

Basically this is the BlinkWithoutDelay approach - lose delay() completely, schedule every action
and test for them every time round loop(). Make sure loop() runs at a high rate.

In your original post you said

Both motors are bipolar stepper motors drawing 1750 mAh

which wasn't true or meaningful - mAh is a unit of charge, not current, and now you say the motors
are 0.33A.... Please try to be complete and accurate because its in your interest!