Setting up serial communication with Dynamixel using Arduino + Dynamixel Shield

I will be using an Arduino UNO connected to a Dynamixel Shield to control an XL330-M288-T servo. I am reading through the “position_mode.ino” code example to understand how serial communication is setup, and I’m not quite sure I understand what is going on.

The example uses software serial setup on pins 7 and 8 for “DEBUG_SERIAL”:

SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
#define DEBUG_SERIAL soft_serial

But it looks like this serial connection is NOT for controlling the dynamixel servo. Instead, it seems it is being used to do serial monitoring on the Arduino IDE via USB, because later, “DEBUG_SERIAL” is used to “print” things (so, I assume this is the serial monitor that appears on my laptop screen):

DEBUG_SERIAL.print("Present Position(raw) : ");

I did not know you could do that! I thought serial monitoring is ONLY through the hard-wired pins ‘0’ and ‘1’. So I guess I’m wrong. So then what I don’t understand is:

  1. How does the Arduino and my PC know that serial monitoring data is being sent using pins ‘7’ and ‘8’. I understand that we created a “soft_serial” object, but how does the controller know that this serial port is to be used for monitoring data only, that will be sent to the PC and not to the servos?

  2. Similarly, how does the DynamixelShield know to take control instructions from the hardware serial port (pins ‘0’ and ‘1’) and not the software serial port that was setup?

  3. If I wanted to switch it and use software serial on pins ‘7’ and ‘8’ to communicate with my servos and hardware serial on pins ‘0’ and ‘1’ to send monitoring data back to the PC, how exactly would I change this code to reflect that setup?

  1. It doesen’t. As far as the Arduino and PC know, both serial ports are just sending data in and out. There isn’t any inherent difference between using the port for data or monitoring. There’s nothing stopping you from sending monitoring data through the DYNAMIXEL serial port or control data through the monitoring port, excepting that it won’t accomplish anything productive.

  2. The DYNAMIXEL Shield is physically wired to connect pins 0, 1, and 2 to the DYNAMIXEL serial ports, and to connect pins 7 and 8 to the UART monitoring port.

  3. The short answer is that you can’t. While it would be technically possible to do so, it would be several orders of magnitude easier to make a custom DYNAMXIEL shield with a layout made for that purpose. Additionally, software serial is way slower than hardware and would likely absolutely tank DYNAMIXEL communications performance.

Nobody has ever asked these sorts of questions here before, as far as I know, and I just wanted to say that they are pretty good questions about the nature of how the DYNAMIXEL shield works. If I misunderstood your questions, or if there’s anything else you’d like to know I’d be happy to answer anything further.