Im currently trying to control two dc motor using the adafruit motor shield to control the movement of this chassis
http://www.pololu.com/catalog/product/1060TReX
However I'm currently confused on how to control two motors through the programming with the use of the motor shield.The pseudo code goes like this and the wiring setup of the motor shield.
for forward movement : two motors turns on in one direction for x amount of time
for reverse movement : two motors turns on in the opposite direction
for left turn 90 degrees : one motor turn in one direction while the other one turns in the opposite direction
for right turn : opposite of the left turn
stopping:both motors turn off
I know I can just use the delay functions to set the time running
Ive done some reading and these are the functions that are included with the shield,however im not sure how I would control two motors since the examples ive seen only uses one.
motor.setSpeed(speed) sets the speed of the motor.
motor.run(FORWARD) makes it go forward
motor.run(BACKWARD) makes it go backward
motor.run(RELEASE) makes it stop
Currently I have a 9v powering the arduino what else power would I need? the chassis has a power source for the two motors
but would i feed this to the motor shield then connect the motor to the shield ? Or I would need 3 independent battery source one for the arduino,one for the shield and one for the motors
thank you for your time and patience
Motor shield two motors
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield two motors
Declare two motors, and send commands to each of them:im not sure how I would control two motors since the examples ive seen only uses one.
Code: Select all
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor4(4);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Dual Motor test!");
// turn on motor
motor1.setSpeed(200);
motor4.setSpeed(200);
motor1.run(RELEASE);
motor4.run(RELEASE);
}
void loop() {
uint8_t i;
motor1.run(FORWARD);
motor4.run(BACKWARD);
for (i=0; i<255; i++)
{
motor1.setSpeed(i);
motor4.setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--)
{
motor1.setSpeed(i);
motor4.setSpeed(i);
delay(10);
}
}
Yes. Feed these to the External Power terminals. Be careful not to reverse the polarity - and don't forget to remove the power jumper.the chassis has a power source for the two motors
but would i feed this to the motor shield then connect the motor to the shield ?
Please be positive and constructive with your questions and comments.