Skip to content

Herkulex servos move in unison

December 2, 2012

The other day, I configured four Herkulex servos for use at 57600 baud, so I could communicate with them from an Arduino‘s software serial port.  Here’s what happened next.

I had previously started on my own Arduino library for communicating with these servos.  Then my brother, whose google-jutsu is apparently stronger than mine, sent me a link to this page.  It turns out that Dongbu has an Arduino HerkuleX library already available, and mine was still at the blinky-light stage, so I decided to download it and give it a try.

To use the library, you instantiate a Herkulex object, and call one of several “begin” methods (depending on which serial port you’re connecting to the servo chain).  You can then call the following methods:

  • torqueOn: activate torque mode
  • torqueOff: deactivate torque mode (free spin)
  • turn: start continuous rotation at the given speed
  • getTurnSpeed: get current rotation speed
  • movePos: move to a position, specified in 1024ths
  • getPos: get current servo position, in 1024ths
  • moveAngle: move to a position, specified in degrees
  • getAngle: get current servo angle, in degrees
  • getStatus: get current error state
  • clear: clear the error state, if any

That’s it — pretty basic stuff.  Each function takes the ID of the servo you want to talk to.  The move, movePos, and turn methods take an optional “play time” (duration over which the motion should be done), and also let you set the LED color.

A few things are missing, in my opinion: no way is provided to get or set any register; you can’t move multiple servos with one command; and you can’t even set the LEDs unless you also issue a move or turn command.  But there’s something to be said for simplicity, too.

The library comes with a test program that lets you interact with a single servo by typing simple commands in the serial window.  After playing with that a bit, I wanted to try controlling all four at once.  I wrote the following Arduino sketch:

#include <HerkuleX.h>

#define RX   10        // Connected with HerkuleX TX Pin
#define TX   11        // Connected with HerkuleX RX Pin

void setup()  
  Serial.begin(9600);    // Open serial communications
  HerkuleX.begin(57600, RX, TX);  // software serial

  // Clear errors on all servos
  for (int i=1; i<=4; i++) HerkuleX.clear(i);

  // Torque ON for all servos

  // Reset all servos to center position, lights on green.
  for (int i=1; i<=4; i++) {
    HerkuleX.movePos(i, 512, 0x60, HERKULEX_LED_GREEN);


void loop()
  for (int i=1; i<=4; i++) {
    HerkuleX.movePos(i, 512 + 64*i, 0x90, HERKULEX_LED_BLUE);

  for (int i=1; i<=4; i++) {
    HerkuleX.movePos(i, 512, 0x90, HERKULEX_LED_GREEN| HERKULEX_LED_RED );

This initializes all four servos to their center position, and then in the main loop, cycles each one between two positions, with a brief delay.  Each servo moves a different distance, but all over the same amount of time (about 3 seconds).  Here’s a video — please forgive the poor quality of the video, which is entirely my own fault.

I inserted a little breadboard wire into each servo horn, to make it easier to see them turning.  You can see that they do all move smoothly, and all arrive at the same time.

The experiment wasn’t entirely without a hitch, however.  It turns out that my cheap 1.5-12V adjustable wall wart couldn’t supply enough current to service all four servos at once when they moved quickly.  With simultaneous quick movements, the voltage would sag and the servos would reboot (which is easy to spot by the white LED flash always displayed on startup).  The wall wart is rated at 0.3A, and these servos can draw about 0.5A each, so I guess this is not too surprising.

I worked around it by using a lower speed (and the fact that this works indicates some nice things about power management in the servos themselves).  For the future, though, I’ll certainly need to bring out a beefier power supply.

All told, the Dongbu Arduino library works as advertised, as do the servos themselves.  I might like to add a few more functions to the library for advanced use, but it’s certainly enough to get started.  Arduino + Herkulex = easy robotic fun!


From → Opinion, Reviews, Tips, Videos

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: