Here is the code I used for testing the motors and the Pololu motor driver. It is a just a simple test that runs each motor from stop to full speed and back to stop over and over.
// Mk.2 motor test. Used the example sketch “Fading” as a basis for this program.
// Connections from Arduino to Pololu motor controller
// Arduino pin 6 connected to motor controller pin 1INa
// Arduino pin 7 connected to motor controller pin 1INb
// Arduino pin 3 connected to motor controller pin 1PWM
// Arduino pin 8 connected to motor controller pin 2INa
// Arduino pin 9 connected to motor controller pin 2INb
// Arduino pin 5 connected to motor controller pin 2PWM
//+5v and GND from Arduino also connected to +5v IN and GND on motor controller
int value = 0; // variable to keep the actual value
int mafPin = 6; // motor a forward
int mabPin = 7; // motor a backward
int masPin = 3; // motor a pwm speed pin
int mbfPin = 8; // motor b forward
int mbbPin = 9; // motor b backward
int mbsPin = 5; // motor b pwm speed pin
void setup()
{
digitalWrite(mabPin, HIGH); // sets the enable input on motor a
digitalWrite(mbbPin, HIGH); // sets the enable input on motor b
pinMode(mafPin, OUTPUT); // sets the digital pin as output
pinMode(mabPin, OUTPUT); // sets the digital pin as output
pinMode(masPin, OUTPUT); // sets the digital pin as output
pinMode(mbfPin, OUTPUT); // sets the digital pin as output
pinMode(mbbPin, OUTPUT); // sets the digital pin as output
pinMode(mbsPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
{
analogWrite(masPin, value); // sets the value (range from 0 to 255)
analogWrite(mbsPin, value); // sets the value (range from 0 to 255)
delay(30); // 30ms delay
}
for(value = 255; value >=0; value-=5) // fade out (from max to min)
{
analogWrite(masPin, value); // sets the value (range from 0 to 255)
analogWrite(mbsPin, value); // sets the value (range from 0 to 255)
delay(30); // 30ms delay
}
}
