http://www.seeedstudio.com/wiki/Motor_Shield_V1.0 - Motor Shield
This motor shield says it will support up to 14 servos and two DC motors. However I can't get the DC motors to work while the servos are attached. The status lights on the motor controller light up but the motors won't work while there are servos in use. If i don't attach the servos in the script, the motors will work. I am powering the motor shield with 12v
#include <Servo.h>
#include <SoftwareSerial.h>
#include "MotorDriver.h"
int speedpinA=9;//enable motor A
int speedpinB=10;//enable motor B
int pinI1=11;//define I1 interface
int pinI2=8;//define I2 interface
int pinI3=12;//define I1 interface
int pinI4=13;//define I2 interface
Servo Yservo; // create servo object to control a servo
Servo Zservo;
int Ypos = 0; // variable to store the servo position
int Zpos = 0; // variable to store the servo position
//Xbee Configuration
#define Rx 6 // DOUT to pin 6
#define Tx 7 // DIN to pin 7
SoftwareSerial Xbee (Rx, Tx);
byte incoming;
byte outgoing;
void setup() {
motordriver.init();
Yservo.attach(4);
Zservo.attach(5);
Yservo.write(180);
Zservo.write(180);
Serial.begin(9600); // Set to No line ending;
Xbee.begin(9600); // type a char, then hit enter
delay(500);
}
void loop() {
motordriver.setSpeed(127,MOTORB);
motordriver.setSpeed(127,MOTORA);
//analogWrite(speedpinA,spead);//AnalogWrite to Generate PWM to control the motor speed
//analogWrite(speedpinB,spead);
if(Serial.available()) { // Is serial data available?
outgoing = Serial.read(); // Read character, send to XBee
Xbee.print(outgoing);
}
if(Xbee.available()) { // Is data available from XBee?
incoming = Xbee.read(); // Read character,
Serial.println(incoming); // send to Serial
if (incoming == 119){ //W
Forward();
}
if (incoming == 97){ //A
Left();
}
if (incoming == 115){ //S
Backward();
}
if (incoming == 100){ //D
Right();
}
if (incoming == 102){ //F
aStop();
Straight();
}
if (incoming == 106){ //J
sLeft();
}
if (incoming == 108){ //L
sRight();
}
if (incoming == 105){ //I
sUp();
}
if (incoming == 107){ //K
sDown();
}
}
}
//Methods to adjust DC Motor power
void Forward(){
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
}
void Backward(){
digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
digitalWrite(pinI1,HIGH);
}
void aStop(){
digitalWrite(pinI2,LOW);//turn DC Motor A OFF
digitalWrite(pinI1,LOW);
}
void Left(){
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
}
void Right(){
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
}
void Straight(){
digitalWrite(pinI4,LOW);//turn DC Motor B OFF
digitalWrite(pinI3,LOW);
}
//Methods to adjust servo position
void sLeft(){
Ypos -= 5;
Yservo.write(Ypos);
}
void sRight(){
Ypos += 5;
Yservo.write(Ypos);
}
void sUp(){
Zpos += 5;
Zservo.write(Zpos);
}
void sDown(){
Zpos -= 5;
Zservo.write(Zpos);
}