Go Down

Topic: ADF Motor shield control incorrect (Read 395 times) previous topic - next topic

selkirk5934

I have an ADF Motor shield V1 and an Arduino Uno controlling two DC motors.  The motors are small low power gear reduction motors.  I am using the AFMotor library.  I used the example MotorTest that came with the library to verify that both the motors worked correctly individually.  Then I modified the code to run both motors.  The problem I have is that when the motors run in the FORWARD direction, they both run as expected.  However, when they run in the BACKWARD direction one motor does not start immediately but jumps to about half speed after a delay.

The motor designated motor2 in the code is the one that is in error.  It does not matter which of the 4 motor outputs it is assigned to the behavior remains the same.  Also motor1 always responds correctly no matter which of the 4 outputs it is attached to.  I have verified that the motor shield output for motor2 is in error.  In BACKWARD the output voltage on the motor connection pins jumps from 0 volts to approximately 3.5 volts (I'm using 5 volt motor supply) while the voltage for motor1 smoothly increases from 0 volts to 5 volts.  In FORWARD motor2 voltage increases smoothly from 0 to 5 volts in parallel with the voltage for motor1.

Have I missed something in the way the AFMotor library is  used?


Code: [Select]

// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#include <AFMotor.h>

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");

  // turn on motor
  motor1.setSpeed(200);
  motor2.setSpeed(200);
 
  motor1.run(RELEASE);
  motor2.run(RELEASE);
}

void loop() {
  uint8_t i;
 
  Serial.print("tick");
 
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  for (i=0; i<255; i++) {
    motor1.setSpeed(i);
    motor2.setSpeed(i);   
    delay(10);
 }
 
  for (i=255; i!=0; i--) {
    motor1.setSpeed(i);
    motor2.setSpeed(i);   
    delay(10);
 }
 
  Serial.print("tock");
 
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  for (i=0; i<255; i++) {
    motor1.setSpeed(i);
    motor1.setSpeed(i);   
    delay(10);
 }
 
  for (i=255; i!=0; i--) {
    motor1.setSpeed(i);
    motor2.setSpeed(i);   
    delay(10);
 }
 

  Serial.print("tech");
  motor1.run(RELEASE);
  motor2.run(RELEASE);
  delay(1000);
}


Dale Gloer

slipstick

Code: [Select]

    motor1.setSpeed(i);
    motor1.setSpeed(i);   

Do you think it would help if one of these was motor2?

Steve

selkirk5934

Steve, you are correct.  When explaining this code to my 10 year old grandson he pointed out my error.  Sometimes you can't see the forest for the trees.

Dale Gloer

Go Up