Hello and thank you in advance for your help. I have a Arduino Duemilanove and an Adafruit motor shield. I am using a 4.5V to 9 V DC motor. My arduino is powered by USB or a 9V battery. The shield and motors are powered by 12 V (8 new AAA batteries in series or one large lead acid battery) in the external power jack on the shield. The shield was built according to the instructions. The LED lights. Servos work fine. When I upload and run this following code, which is an example in the AFmotor library I downloaded to use the shield, the motor barely spins or doesn't spin at all. It does not accelerate or decelerate over the entire acceleration and deceleration periods. I confirmed on an oscilloscope that the PWM on that motor channel was working. However, with the test code pasted below, it only provided 1V of power according to the oscilloscope, which is insufficient to run the motor. I added four lines to the code and the shield worked fine. I marked these lines below. Why is this necessary? Has anyone else experienced this problem? And when must extra motor.run() commands be used?
Code:// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
#include <AFMotor.h>
AF_DCMotor motor(4);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
// turn on motor
motor.setSpeed(200);
motor.run(RELEASE);
}
void loop() {
uint8_t i;
Serial.print("tick");
motor.run(FORWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
motor.run(FORWARD); //was added here
delay(10);
}
for (i=255; i!=0; i--) {
motor.setSpeed(i);
motor.run(FORWARD); //was added here
delay(10);
}
Serial.print("tock");
motor.run(BACKWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
motor.run(BACKWARD); //was added here
delay(10);
}
for (i=255; i!=0; i--) {
motor.setSpeed(i);
motor.run(BACKWARD); //was added here
delay(10);
}
Serial.print("tech");
motor.run(RELEASE);
delay(1000);
}