Using Atmega32u4

You can use pretty much any Atmega microcontroller to talk to Dynamixel servos. It doesn't have to be a Robotis controller board, or an Arbotix. It can be a simple USB Atmega break-out board, or even a simple Arduino board. However, you have to make some changes to the software; the Serial class from Arduino does not work very well on its own.

Electrical Interface


The Atmega is rated for 25 mA of normal current on a pin, with an absolute maximum rating of 40 mA. I have found that about a 70 Ohm resistance will give you sufficient protection against over-current, while still leaving you able to drive a full robot worth of Dynamixel servos at 2 Mbit speed. Similarly, you want to tie the RXD pin to the TTL bus with another resistor; I use 70 Ohm there too for symmetry but a bigger resistor could probably still work. The reaon to do this is to protect the Atmega from possible "accidents" on the TTL bus.

The easiest way to connect an existing microcontroller to the Dynamixel bus is to cut a Dynamixel three-wire cable in half, and strip and tin the ends of the wire. The three wires are in the same order as a hobby servo: Ground, Power, and Control, although for Dynamixels, Control is UART serial commands.

Software Interface
The protocol for Dynamixels is well documented on the Robotis support site and pretty simple. Starting with two 0xFF bytes (which gives servos time to wake up and synchronize to the incoming data,) the rest of the data is ID, Length, Instruction, Data, Checksum, where ID is the ID of the target servo, or 254 for a broadcast command.

To send a command, you want to turn off the receiver circuit of the Atmega, turn on the sending circuit, and loop through your data, pushing it out the serial port. For faster data rates, you want to do this synchronously, with interrupts disabled, rather than relying on interrupt-driven buffered I/O. Once your command has been sent, you should turn the UART around; disable transmitting (wait for the final byte to complete sending first!) and enable receiving, and then wait for the response packet if one is due.

Using a Response Level of 1, meaning a servo will not respond to a write command, only to a read command, is a useful way of improving throughput on the TTL bus. Also, turning down the "response delay" in the servo to between 0 and 10 microseconds (values from 0 to 5) is another good way to improve timing.