Dynamixel Servo Control Issues

I'm attempting to control a dynamixel servo with an Arduino mega but I'm not having much luck. To start with, I'm just trying to make the on-board LED blink.

  1. I have a scope on the output of the RS-485 chip and my data at least looks right. This lets me know that the hardware connections should be where they need to be. Otherwise I wouldn't be getting anything out of the ST485.
  2. The servo powers up properly, as I can see the LED blink when it receives power.
  3. I know that the servo functions properly, as I can plug it into a CM-700 and control it through the manager
  4. Using the DynamixelSerial1 library and code below.
  5. Yes, I have attempted switching A and B on the RS485 bus.

Any ideas on what I should try next?

#include <DynamixelSerial1.h>

void setup(){
Dynamixel.begin(1000000,2);  // Inicialize the servo at 1Mbps and Pin Control 2
delay(1000);
}

void loop(){
    Dynamixel.ledStatus(1,OFF);
    delay(500);
      Dynamixel.ledStatus(1,ON);
        delay(500);

}

need to post a link to the data sheet of the device you are using.

is the dynaixel a serial device ?

if it is, try using simple serial code and not the library. that way you can see every step of the sketch and would have much better grasp of each function.

not sure why there is a delay in void setup()

I do not have one of these, so am only taking shots at this.
it is a serial device. you have not called any serial operations. it may be that everything is in that one library, another reason to break it down into steps.

can you talk to or control any other device on the RS485 ?

since there are no other people responding, you would be well served to google arduino and dynamixel and the see what others have posted.

this one has some code that might help.

http://robottini.altervista.org/dynamixel-ax-12a-and-arduino-how-to-use-the-serial-port

The Dynamixel servo is an RS-485 model. Part number MX-28R

Product Page:

My first attempt was to control it directly instead of using a library but I didn't have any luck. I figured that there was some fundamental problem that would be solved using canned code. My original code is below

/ *******************************
// DEFINES
// *******************************

#define RS485_EN 7     // Hardware location of enable line
byte startAddress;
byte servoID = 0x07;    // Servo Address
int i = 0;             // program counter
byte ledOn = 0x01;
byte ledOff = 0x00;

//*************************************************************
// FUNCTION: Activate Servos
// RETURNS: Nothing
// DESCRIPTION: Activates our servos
//*************************************************************
void activateServos(byte servoID, byte newValue) {
  
  int checksum_ACK;
  byte notchecksum;
  unsigned char length = 0x04;
  startAddress = 0x19;     // Turning on led
   
  checksum_ACK =  servoID + length + 0x03 + startAddress + newValue;
  notchecksum = ~checksum_ACK;
  
  //noInterrupts();
  
  // Transmission routine
  digitalWrite(RS485_EN,HIGH);      // 1.  Set direction of the RS-485 COM
  delay(15);                        // 1a. Allow this to take effect
  
  Serial3.write(0xFF);              // 2. Sync Byte 1
  Serial3.write(0xFF);              // 3. Sync Byte 2
  Serial3.write(servoID);           // 4. Dynamixel Servo Address
  Serial3.write(length);            // 5. Length of packet
  Serial3.write(0x03);              // 6. Instruction
  Serial3.write(startAddress);      // 7. Start address for data to be written
  Serial3.write(newValue);          // 8. Apply new value of register
  Serial3.write(notchecksum);       // 9. Send the checksum
  
  delay(3);                         // 10. Allow last byte to go through
  digitalWrite(RS485_EN,LOW);       // 11. Set direction of RS-485 COM
    //interrupts();
}

//*************************************************************
// FUNCTION: Setup
// RETURNS: Nothing
// DESCRIPTION: Initial setup of our pins and COMs
//*************************************************************
void setup() {
  Serial3.begin(57600);
  pinMode(RS485_EN, OUTPUT); 
}

//*************************************************************
// FUNCTION: loop
// RETURNS: Nothing
// DESCRIPTION: Our main program loop
//*************************************************************
void loop() {
  
  //Transmission section
  delay(1);

  if (i%2 ==0){ 
    activateServos(servoID, ledOn);
    delay(900);
  } else {
    activateServos(servoID, ledOff);
    delay(900);
  }

   i++;
  if (i>1000){
    i=1;
  }  
}

I've verified operation of the RS485 bus. I'm using 120-Ohm termination resistors

Transmitter (Arduino Uno)

#define RS485_EN 2
unsigned char counter = 0;

void setup() {
  Serial.begin(57600);
  pinMode(RS485_EN, OUTPUT);
  digitalWrite(RS485_EN, HIGH);
}

void loop() {
  
  delay(15);
  Serial.write(counter);
  delay(3);
  //digitalWrite(RS485_EN, LOW);
  delay(200);
  
  counter = counter + 1;
  
  if (counter > 250)
    counter = 0;
}

Receiver (Arduino Mega)

#define RS485_EN 2
unsigned char rxByte;
unsigned int counter = 0;

void setup() {
  Serial.begin(57600);
  Serial1.begin(57600);
  pinMode(RS485_EN, OUTPUT);
  digitalWrite(RS485_EN, LOW);
}

void loop() {
  
  // Check for available packets
  if (Serial1.available() > 0) {
    rxByte = Serial1.read();    
    Serial.println(rxByte);
    counter = 0;
  }
  else {
    counter = counter + 1;
    if (counter > 50000) {
      Serial.println("[nd]");
      counter = 0;
    }
  }
   
}