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:
-
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?
-
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?
-
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?