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);
}