Making the Motor Cable
To use the LEGO NXT servo motor with the robot
board, I needed a simple way to connect it to the sensor
inputs and motor driver outputs. I don’t like to chew up
cables, especially odd cables like the six-pin RJ11. So, I
looked for a way to interface this motor to my board that
was nice and clean. Microchip’s standard PIC programmer
cable is a six-pin RJ11 and this was the only cable of that
type that I had, so I searched for something else that used
that cable. On the SparkFun site (
www.sparkfun.com), I
found the Olimex ICSP breakout board (part Dev-08108)
which had a short six-pin RJ11 cable and two other connectors that would take two different pin pitch connectors. I
used the connector with the .1” pin pitch to connect the
signal lines to my board. Figure 3 shows how I used this
breakout board to connect the RJ11 cable to my board.
The RJ11 cable did not exactly match the plug on the
motor. I needed a slight modification to get everything
working right. Figure 4 shows what the motor connector
looks like and the pin-out of the signals that are going to
be used — which is all of them.
If you look at any RJ11 cable, you’ll see that the
retainer clip (the thing that goes click when it is snapped in)
is centered in the Olimex cable. That clip isn’t centered on
the LEGO NXT servo motor. This required some basic plastic
surgery (pardon the pun). I modified the cable by removing
the retainer clip and carving out some of the connector
with a file. This is very difficult to explain in words, so look
at Figure 5 to see what I’m talking about. The bold black
line in Figure 5 shows the final form of the connector; the
red line shows the part that was removed to get it to fit
into the LEGO servo motor connector. It is possible that I
could have left part of the retainer clip still on the cable,
but even without this the cable fits quite snugly into the
jack. You only need to modify one end of the cable.
The other end fits as expected into the Olimex ICSP
breakout board.
As previously mentioned, all six signal wires are used
to run the motor and get the quadrature feedback to the
robot board.
Everything is Connected.
Now What?
We have the motor PWM inputs connected to a
754410 one amp H-bridge chip that is controlled by two
of the PWM outputs of the ATMEGA168 chip. We’re only
using one channel here since I’ve only got one motor. It
isn’t a very exciting robot, but it is still cool to see one’s
labor rewarded with a correctly functioning project. I built
this project using avr-gcc 4. 3.0 in the Eclipse Europa IDE
using the Eclipse AVR plug-in. You should be able to port
it to your favorite environment with little effort.
We all know how PWM works to adjust the motor
speed, so I won’t go into detail. The function InitMotors() in
the source code atm168.c shows how this is done. The
Figure 3. Olimex PIC ICSP breakout board.
complete source code for this project can be downloaded
from the
www.servomagazine.com site under Mr. Roboto
as atm168.zip. Remember that it is C code written in
avr-gcc — a free compiler for the Atmel AVR microcontrollers. When you look at the SetMotorSpeed() function,
you might wonder why I change bits in the TCCR0A register
when I change directions (see Listing 1). I do this because
we can save an I/O line from the ATMEGA168 by using a
single output to enable both H-bridges (1,2EN and 3,4EN)
Figure 4. LEGO NXT servo motor connector and pin-out.
SERVO 07.2009
15