Hello everyone,
I have been troubleshooting all day trying to solve a little problem I have run into. I own a TB6612FNG Dual Motor Driver Carrier from Pololu, and have been working on a project that involves the use of that motor driver and a servo.
If I only include code to run the motor driver:
#define MOT_IN_A1 13 // motor input 1
#define MOT_IN_A2 12 // motor input 2
#define MOT_A_PWM 10 // motor speed, determined by PWM
#define STANDBY 11 // motor driver enable/disable
#define LED 9 // status LED
void setup(){
DDRB = 0xFF; // set all port B pins to OUTPUT mode
digitalWrite(STANDBY, HIGH); // enable motor driver
digitalWrite(LED, HIGH); // turn status LED on
analogWrite(MOT_A_PWM, 100); // set speed for motor driver to 100 (of a maximum of 255), approx. 40% power.
}
void loop(){
digitalWrite(MOT_IN_A1, HIGH);
digitalWrite(MOT_IN_A2, LOW);
delay(2000);
digitalWrite(MOT_IN_A2, HIGH);
digitalWrite(MOT_IN_A1, LOW);
delay(2000);
}
Everything works perfectly.
However, as soon as I create a Servo object and attach it to a PWM enabled pin (pin 3 in this case):
#include <Servo.h>
#define MOT_IN_A1 13 // motor input 1
#define MOT_IN_A2 12 // motor input 2
#define MOT_A_PWM 10 // motor speed, determined by PWM
#define STANDBY 11 // motor driver enable/disable
#define LED 9 // status LED
Servo s;
void setup(){
s.attach(3); // digital PWM enabled pin 3 on arduino
DDRB = 0xFF; // set all port B pins to OUTPUT mode
digitalWrite(STANDBY, HIGH); // enable motor driver
digitalWrite(LED, HIGH); // turn status LED on
analogWrite(MOT_A_PWM, 100); // set speed for motor driver to 100 (of a maximum of 255), approx. 40% power.
}
void loop(){
digitalWrite(MOT_IN_A1, HIGH);
digitalWrite(MOT_IN_A2, LOW);
delay(2000);
digitalWrite(MOT_IN_A2, HIGH);
digitalWrite(MOT_IN_A1, LOW);
delay(2000);
}
The motor driver no longer moves the motor.
I do have a good power supply so I do not believe that is the problem.
I really have no idea why this is happening, and my google-fu hasn't brought anything relevant up. Thanks to anyone who can help =).