Friday, February 19, 2010

Arduino and Pololu Motor Controller

Arduino and the Pololu Motor Controller - A tutorial for the beginner.


Let's say you wanna work with robots using the arduino but don't where to start and need some help.

Well you found the right blog to do that.

Here's what you need:
  1. Arduino
  2. Pololu Motor Controller preferably Pololu Low Voltage Dual Serial Motor Controller
  3. Gearbox and Motor- Preferably Tamiya Gearbox which can be obtained from Pololu.com
  4. A bread Board
  5. A Power Supply for the motor controller or a battery pack - Voltage rating between 5-7 volts
  6. Wires to connect everything together.

After you got everything now let's go...

Step 1 Assembly

Assemble the gearbox and solder cables to the motor controller to avoid shorting of the controller. (This stuff is expensive and shorting stuff sucks)
Connect everything together and make sure to tie the ground of the Arduino with the Motor Controller ground to eliminate noise and to complete the circuit. Very Important!


Step 2 Programming the Arduino


Program the Arduino and make sure you do it well. Fortunately, with all of the previous posts submitted, a sample code is always provided for convenience below.

Note: Programming the Pololu motor controller isn't tricky but you have to know what you are doing.

  • First you set the reset pin of motor controller to HIGH so you can talk to it.
  • Then you have to send a command that tells the motor controller you are commanding it (0x80);
  • then a parameter command or instructions of what to do (0x00 = move);
  • then a motor selection command (see code)
  • then the speed for the motors (see code)
If you are using more than one motor controller, then I suggest programming one controller at a time. You also need to refer to the manual for the motor controller configuration. If you need help you can contact me as well on this post.


*** start of program
int resetPin = 7; //need to have a reset pin so you can control motors

void setup()
{
delay(1000); //delay for 1 second
Serial.begin(9600); //Serial set to 9600 baud
pinMode(resetPin,OUTPUT); //set the reset pin to HIGH to program
delay(1000); //delay for 1 second

//move motor(s)

}

void loop()
{
digitalWrite(resetPin,LOW); //reset the motorcontroller
delay(100); //delay for 1 msec
digitalWrite(resetPin,HIGH); //intitiate motorcontroller
delay(1000); //delay 1 second


//Serial.print(0x80,BYTE); //command motorcontroller
//Serial.print(0x00,BYTE); //move parameter

//**motors are configured as motors 2 and 3 by default 2 is right side and 3 is left side
//Serial.print(0x05,BYTE); //right side motor move forward
//Serial.print(0x04,BYTE); //right side motor move backward

//Serial.print(0x07,BYTE); //left side motor move forward
//Serial.print(0x06,BYTE); //left side motor move backward

//Serial.print(0x3F,BYTE); //speed setting command 0x7F = full speed; 0x3F half speed; 0x00 speed off



//both motors in sequence allowing both motors to move
Serial.print(0x80,BYTE); //command motorcontroller
Serial.print(0x00,BYTE); //move parameter
Serial.print(0x05,BYTE); //right side motor move forward
Serial.print(0x3F,BYTE); //speed setting command 0x7F = full speed; 0x3F half speed; 0x00 speed off

Serial.print(0x80,BYTE); //command motorcontroller
Serial.print(0x00,BYTE); //move parameter
Serial.print(0x07,BYTE); //left side motor move forward
Serial.print(0x3F,BYTE); //speed setting command 0x7F = full speed; 0x3F half speed; 0x00 speed off


delay(3000); //let it run for 3 seconds

}

***end of program

Step 4 Run it


When uploading the program do not attach the motor controller because it will screw up the motor controller.

After uploading the program, attach the motor controller and power supply and watch it go.

Final Result

Here is everything put together




















These two photos show the motor controller and its respective LEDs. The LEDs on the photo on the right shows both LEDs lighted meaning both motors are moving). When green it is moving forward, red is moving in reverse. One of the LED will glow if you command for one of the motors to move.



Have fun and post your comments if you are having problems.

No comments:

Post a Comment