:: HOME.
:: NEWS.
:: REVIEWS.
:: EXAMPLES.
:: PROJECTS.
:: ELECTRONICS.
:: MICROCONTROLLERS.
:: EVENTS.
:: BOT SWAP.
:: CLUBS & GROUPS.
:: ROBOTICS FORUM.
:: --Write for ROBO101--
--LOGIN--
Email address:
Password:
JOIN ROBO101.COM

 

::Pololu Micro Dual SerialMotor Controller with Arduino | Microcontrollers | Home



By: sweddle


It seems like I have few serial h-bridge motor drives in my arsenal of parts for building robots, but I'm not one to pass up an opportunity to work with a new one, especially a nice small one with a good bit of power for its size. So when the Pololu Micro Dual Serial Motor Controller arrived I was exited to dig in.  First off, it really is a tiny package -- about 1inch by half an inch -- and the leads set in my breadboard nice and snug; not too short like some items have a tendency to do. I'm commanding the Pololu Micro Dual Serial Motor Controller using my beloved Arduino (Diecimila) -- it's an open source microcontroller that’s quickly taking over such popular controllers like the BS2.

I start by hooking up pins 1 and 2 on the Arduino to pins 4 and 5 on the motor controller. Pin 1 on the Arduino is TX serial out and pin 2 I will be use to toggle the rest (pin 5) on the motor controller. For now I’m going to power the motor controller with the Arduino’s 5v source that is provided by the USB port on my PC; this is done by attaching wires from the Arduino’s 5v to pin 1+(motor suply 1.8-9.0 V) and pin 3+(logic supply 2.5-5.5V) then GND to pin 2- on the motor controller.  I know this may be taxing the USB port a bit, but as I'm simply testing and using small motors, I’m fine with it for now (just hoping nothing gets too hot). Woohoo, almost ready to code, so I attach a small motor to pins 6 and 7 and I’m ready to start coding.

 Pololu Micro Dual SerialMotor Controller with Arduino.

Now I’m still a bit new to the Arduino, having come from the easy world of the Basic Stamp2 in which to send serial data out on any pin is simply:

serout 2, 32, [$80]
Command pin, baud rate, [hex data] (NOTE: 32 specifies the baud rate to be 19,200)

Well this is not bad...but the Arduino unfortunately does not at this time have a PBASIC compiler, so the code will be done in a C/Java-like language called Processing.  Fortunately, it's easy to warm up to, plus I think it's best to get down to a low level language like C to really take full advantage of your microcontroller. With that said here's what is needed to get the data sent out to pin 2 on the Arduino.

//#### START Arduino Pololu serial code ####


// Name the Motor reset pin.
int motor_reset = 3;

// Run once, when the sketch starts.
void setup()

{
            // Set serial to 9600 bps
            Serial.begin(9600);
            // Set motor reset Pin to output mode. (We use the pin name not number)
            pinMode(motor_reset, OUTPUT);

         //have no idea
        unsigned char buff[6];       

            // Reset the motor controller.
            digitalWrite(motor_reset, LOW);
            delay(10);
            digitalWrite(motor_reset, HIGH);

            // Reset delay befor sending commands.

            delay(100);

            // Setup the buffer with the serial command to spin the motor forwards.

            buff[0]=0x80; // Start byte (The Pololu serial motor controller must always have Hex 80 first)
            buff[1]=0x00; // Device type byte (0 lets the motor controller know it's being sent a command)
            buff[2]=0x01; // Motor number and direction byte (See below "THE TRICK MOTOR COMBO NUMBERS")
            buff[3]=0x100; // Motor speed "0 to 128" (100 is 64 in hex)  

            // Link the buffer bytes to gether so they all go ut at the same time.

            for(int i=0;i<4;i++)

        {
            // WOOHOO!! Let's send the command out the serial pin (Serial.print by default goes out PIN 2)
            Serial.print(buff[i],BYTE); 
        }

}

// Run over and over again

void loop()

{
// We don’t really make use of the loop here, but both the compiler and Arduino needs it.
}

//#### END Arduino Pololu serial code ####

-CODE NOTE-

THE TRICK MOTOR COMBO NUMBERS:

Pololu did something kind of cool and yet kind of confusing here. Instead of sending a byte of data for the motor number and another byte for direction, they combined the two bytes into one.  This is nice, but can be a bit confusing, as our controller has motor 0 and motor 1 hookup wires, but in code to control motor 0 we must use a 0 or 1 and to control motor 1 we send a 2 or 3. (More to come!!!)

Shane W - Date 04/10/2008

.

Comments (Add a Comment)
Add Comment
YOU MUST BE LOGGED IN TO ADD COMMENTS
-Login-
-Join-
 

Contact us  |  About us  |  Site Map   |  Home