Each Dynamixel device must have a unique device ID. From the factory they all have an ID of 1, so if you connect two of them together there will be a device conflict. The CM-900 can change the device ID by writing to the new ID address (3) on the servo through the RS485 bus.
- Connect a dynamixel servo (AX-12+) to one of the TTL connectors on the board.
- Insert a 12V power supply into the 5.1mm barrel connector on the CM900 board.
- Connect a USB->TTL device to the Zigbee port of the CM-900 board. This could be either a Robotis BT-100A board or any other USB -> TTL board. We will be using the CP2102 USB-TTL board.
- Enter the code shown below into the IDE window.
- Setup your board as the compiler target by selecting “Tools” -> “Board” -> “Robotis CM-900”
- Choose the appropriate port by selecting “Tools” -> “Serial Port” -> the port number indicated by your device manager when you installed the VCP driver in the getting started section above.
- Press the Arrow Icon just below the menu bar. The IDE will report that the program is being sent to the CM-900 board and will report “Excute new application” when it is done.
- You will observe that a device list is enumerate on your Serial terminal which contains the new device.
Explaining the code:
- Setup the desired IDs using the CurrentID and NewID variables.
Setup: Setup is run once when either the CM-900 is powered on or the reset button is pressed.
- dxlBegin() This function initializes the dynamixel bus and creates an object called Dxl which has a set of functions associated with it. See Table 1 below for a list of these functions.
- Serial2.being(57600) This function initializes the serial debug port to a baud rate of 57600.
- Dxl.writeByte( CurrentID, 3, NewID ); This command writes a Byte instead of a word. Up to this point we have used the Dxl.writeWord() command. A word consists of two bytes and thus fills two address on the Dynamixel. In this case we only want to write the NewID to the ID register(3) of the Dynamixel at CurrentID.
- Note the dxlBegin and writeWord commands require some time to initialize so there are delays built in to allow this to work properly.
Loop: Loop runs continually as long as the CM-900 is powered. Think of it as a while loop with no termination condition.
- Serial2.print(“Goal Position : “); The Serial2.print command prints something to the serial port. The print command can only take a single string or variable and doesn’t have powerful parsing abilities.
- The remainder of the code loops over the first 32 dynamixel devices and displays if they are present and their type.