Adafruit Motor Shield V2 - Two DC motors simultaneously

Hi,

I am using Arduino UNO R3 for my first robot project.

I have connected two DC-motors (Luxorparts robot wheel, 3-6 V) to my Adafruit Motor Driver v2 on motor port 1 and 4. I have also tried motor port 2 with the same outcome.

When I run my Arduino, first one motor spins and then after a while the other one starts. The problem is that since each motor controls a wheel I wish the motors to operate simultaneously when the robot is driving forward but I do not seem to get it to work.

The system is powered with a wall adapter connected to the Adafruit motor shield DC jack with the VIN socket jumpered. The power of the adapter is 6V/500 mA.

Any suggestions on how to get the motors to run at the same time? See code below.

Thanks in advance!

Matt

Code:

#include <Wire.h>
#include <Adafruit_MotorShield.h>

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_MotorShield AFMS2 = Adafruit_MotorShield();

// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Select which ‘port’ M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);

// You can also make another motor on port M2
Adafruit_DCMotor *myOtherMotor = AFMS2.getMotor(4);

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
//Serial.println(“Adafruit Motorshield v2 - DC Motor test!”);

AFMS.begin(); // create with the default frequency 1.6KHz
AFMS2.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz

// Set the speed to start, from 0 (off) to 255 (max speed)
myMotor->setSpeed(150);
myOtherMotor->setSpeed(150);

myMotor->run(FORWARD);
myOtherMotor->run(FORWARD);

myMotor->run(RELEASE);
myOtherMotor->run(RELEASE);
}

void loop() {

uint8_t i;

myMotor->run(FORWARD);
myOtherMotor->run(FORWARD);

for (i=0; i<255; i++) {
myMotor->setSpeed(i);
myOtherMotor->setSpeed(i);
delay(10);
}

for (i=255; i!=0; i–) {
myMotor->setSpeed(i);
myOtherMotor->setSpeed(i);
delay(10);
}

myMotor->run(BACKWARD);
myOtherMotor->run(BACKWARD);

for (i=0; i<255; i++) {
myMotor->setSpeed(i);
myOtherMotor->setSpeed(i);
delay(10);
}

for (i=255; i!=0; i–) {
myMotor->setSpeed(i);
myOtherMotor->setSpeed(i);
delay(10);
}

myMotor->run(RELEASE);
myOtherMotor->run(RELEASE);
delay(1000);
}

How many motor shields? Your code says there are two shield objects. But since they are both on the default address both those objects refer to the same shield.