Go Down

Topic: Dynamixel Servo Library (Read 20867 times) previous topic - next topic


Jul 26, 2012, 06:27 pm Last Edit: Jul 27, 2012, 01:40 pm by Flex Reason: 1
Hello All,

I have recently been playing with the new Dynamixel MX-28T Servos http://www.robotis.com/xe/dynamixel_en.
Unfortunately because they are fairly new there isn't much information online about them, and more importantly how to use them with an Arduino!

It took a bit of research and a little hacking to get them working, so I thought I would save others the trouble of going through the same and provide some instructions.
The first thing that made things alot easier was that a developer by the name of Pablo Gindel had already written a library for Dynamixel's previous line of servos, the AX-12's.
Here is a link to his page which contains the download and some simple instructions - http://www.pablogindel.com/informacion/the-arduinodynamixel-resource-page/.

However all is not as simple as it may first seem. This library is almost 2 years old, and the instructions are now incorrect and require a little bit extra effort to get working.

So the first thing to do is download the file and place the ax12 folder in the /libraries directory in your Arduino IDE install directory.
Now we need to update it.
The change is rather simple, open the ax12 folder you have just copied and open the ax12.cpp file using a text editor.
Find the "wiring.h" include, and change it to "Arduino.h".
Save the file, and close it.

The next alteration must be made to core Arduino IDE files. I must point out that this change allows this library to work, but I don't know what effect it has outside the use of these servos.
You need to find the HardwareSerial.cpp file, you should find it in /hardware/arduino/cores/arduino folder of you Arduino IDE install directory.
This change is documented in the original instructions but unfortunately the file has changed since and the code you are meant to comment out no longer exists.
The code you need to comment out looks like this:

Code: [Select]

 unsigned char c = UDR1;
 store_char(c, &rx_buffer1);

This modification is necessary as the ax12 library rewrites how the serial port is used. I should mention that obviously you are going to be controlling the Dynamixel servos using the serial port (TX1 and RX1 on the Mega, TX and RX on anything else), I would therefore strongly suggest you use an Arduino Mega for your project as it has multiple serial ports and still allows you to debug through the USB serial port. I have got this working on a Duemilanove though so it's not a problem, just remember to unplug the tx and rx wires connecting the Arduino to the servo when downloading a new program, don't use any serial communications (take a look at SoftwareSerial), and you will also need to comment out more lines in the HardwareSerial.cpp file - everything after the store_char function up to the serialEventRun function. For the current version this is lines 88 - 160.

OK and finally remember to common your grounds! The ground on the Arduino must be connected to the servo ground otherwise you will find that communication is very intermittent (if at all).

I hope this very quick guide has helped a few of you, because I failed to find anything on the internet that was recent enough to work easily. This should work with all Dynamixel servos - AX MX RX and EX. Although if you choose to use the RS485 models (4 wire) rather than the TTL models (3 wire) you will have to use the adapter which can be found in Pablo Gindel's original link above.

Good luck!



The only issue with the Savage Electronics library is that it requires extra hardware to work.
The one I recommended doesn't need anything.

Hi Flex,

I am also trying to connect a MX-28T servo to an Arduino, but have had no luck. I followed the instructions carefully about changing the "Arduino.h" includes and commenting out the lines in the HardwareSerial.cpp, but I think my wiring is the problem.

When I load the program into my Arduino Mega 1280 using the Arduino 1.0.1 IDE, my serial monitor says the following:
deteccion: 0
ID detectado: 1
delay: 0
error lectura: 1920

posicion: 0
velocidad: 0
carga: 0

This is the same output as if I were to run the sketch with absolutely nothing connected. Here is how my wiring is set-up:

I chained 5 batteries in series to raise the voltage up to 12.71 since the recommended voltage of the MX-28 is 10-14.8 volts and the Arduino could only supply 9v.

The Arduino is being powered by the USB.

Ground is connected between the Arduino ground pin, the battery's ground, and the servo ground pin. I heard the ground between the Arduino needs to be connected the ground of the servo's.

The Tx1 and Rx1 are connected in the same row of the breadboard as the data pin for the servo.

Any help would be very useful!


-Alonso Martinez

I also tried the following things:

changing my baud rate to 57600 since I read that it's the default for a brand new the MX-28.

AX12::init (57600);

Instead of using Pablo's autoDetect function, hard coding the servo ID to 1, but no luck =(

motor.id = 1;




The only issue with the Savage Electronics library is that it requires extra hardware to work.
The one I recommended doesn't need anything.

I are right. But the  MX28 costs about 200$, the extra hardware required by Savageelectronics library costs about 1$. I think it is not too much.  :smiley-mr-green:


I am wondering, anyone tried to write the source code firmware in c of Mx28 ?


changing my baud rate to 57600 since I read that it's the default for a brand new the MX-28.
AX12::init (57600);

Hi Amartin2,

Sorry for the late reply, I don't check this forum very often.
Sorry I didn't make it clear in the instructions, you need to use AX12::init(1000000) because the library is designed to work at that speed.
This means that you need to change the baud rate of the dynamixels to 1Mbps. The only way I was able to do this was using their Dynamixel2USB adapter.
I know its annoying that you have to buy yet another piece of kit, but at least you only have to buy one.


Does this library work for Arduino Uno? Because I tried to this but in my hardware/arduino/core/arduino, there is no HardwareSerial.cpp file. I only have HardwareSerial.h file and I don't know what to do with that. Please help. Thanks.

Hello BeepBoop,

The Arduino Uno only has one serial output (Tx and Rx) and I believe that this library needs to have at least two.

I would read all of the comments in Pablo Gindel's website and look for comments using Arduinos with one serial port.  I remember seeing plenty.

What Dynamixel are you using? if you are using the MX-28 then you need a library that Pablo hasn't released yet that I can pass along.



Hi Amartin2,

Ah yes, I am using the Dynamixel MX-28T. I would greatly appreciate it if you could share that library with me. Please and thank you! And I will comb through the comments now....although since I'm a complete noob to Arduinos, I might not really understand it. Could you by any chance explain what the Tx and Rx are and perhaps why it matters? Thank you once more.


Hallo, I have testet it, but my MX-28 do not run.

I have an arduino Uno and then the
Driver Board, but nothing happen wenn I start he sketch (serial Monitor).

I have pluged in 7.2V to the Driver Board.

Can anybody help me?


Hey druckgott,

The current release of the library doesn't work with MX-28, however he does have a new version that works that he hasn't released.

I would email Pablo Gindel and ask him if he could send you a newer version.

When I find time, I will translate the code into english and make a video tutorial so the learning curve for manipulating Dynamixels with Arduino is  less steep.



Hi Flex

Here's a project that seems to have a library for the MX-28


See the file list for: Dynamixel_Serial - V2.0.zip


Hi Flex

Here's a project that seems to have a library for the MX-28


See the file list for: Dynamixel_Serial - V2.0.zi

thx now its running.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131