/Arduino_XM430_Library

A minimal arduino library to control the dynamixel XM series servomotors

Primary LanguageC++

Arduino_XM430_Library

A minimal arduino library to control the dynamixel XM series servomotors.
The library use the protocol 1 to communicate with the motors, a complete description of this protocol is available HERE, and the control table for the XM430 motors can be found HERE. The library was tested on an Arduino Uno for a Camera stabilization project.

This motors use the RS485 serial communication standard to communicate, thus we need to generate compatible packet and signal. This required an external hardware in order to convert the TTl signal from the arduino to RS485 of the motor. The chip is the MAX485 and can be found for a very affordable price on Amazone or so. The following image showes the wiring:


The library generate the packet and then send them though the SoftwareSerial so we are still able to communicate and getting feed back from the arduino. You can also normally connect other motor on the second port.

Last update:

  • Add synWriteFunction.

Ongoing development:

  • Read statuspacket / read instruction : currently encounting issue, the serial does not read any status packet...
  • PID setting
    If you want to add any function, please feel free to ask or help :)

Code example

#include <XM430.h>
#include <SoftwareSerial.h>

//Software Serial (RX, TX)
SoftwareSerial toRS485(11, 10);

//motorID
byte servo3 = 0x03;
byte servo1 = 0x01;

XM430 gimbal(&toRS485);

void setup() {
  //Start the Serial communication: One for the Nano communication, and the other for the RS485
  Serial.begin(9600);
  gimbal.BeginRS485(57600);
  //Enable Torque, without this function the motors will not move.
  gimbal.TorqueEnable(servo3, ON);
}

void loop() {
  Serial.println("Led on");
  gimbal.LedWrite(servo3, ON);
  gimbal.Goto(servo3, 1000);
  delay(1000);
  
  Serial.println("Led off");
  gimbal.LedWrite(servo3, OFF);
  gimbal.Goto(servo3, 0);
  delay(1000);
}

API Description

  • XM430(SoftwareSerial * ss)
    Class constructor using the SoftwareSerial pointer

  • void BeginRS485(uint32_t baudrate)
    BeginRS485: start the SoftwareSerial communication

  • void LedWrite(byte servoID, byte newValue)
    LedWrite: write the newValue (ON-OFF) at Led address (65->0x41)

  • void TorqueEnable(byte newValue)
    TorqueEnable: write the newValue(On-OFF) at the torque address (64->0x40)

  • void int32Splitting(uint32_t Position, unsigned char bytes[4])
    int32Splitting: decompose the uint32_t position into 4 bytes by masking and shiffting

  • void Goto(byte servoID, int position)
    Goto: write the 4 byte position at the goalposition address (116->0x74). The protocol use MSB first.

  • void SyncWrite(byte servoID1, int position1, byte servoID2, int position2);
    SyncWrite: use the broadcast ID and the syncwrite instruction to write goalposition of 2 motors in only one packet. Use to reduce communication time.
    Input: motorID and the wanted position.