Need help in connecting Arduino with Dynamixel RX-64

Hi,

I need help to connect my Arduino Mega with dynamixel RX-64. Basically I tried to use RS-485 breakout and follow this schematic for connection (http://www.pablogindel.com/informacion/the-arduinodynamixel-resource-page/) and I use below code to try to Ping the motor

//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Initial condition
//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

const int RTSpin = 2;   //1= transmit, 0 =receive
byte ping  =0x01;
byte READ  =0x02;
byte WRITE =0x03;
byte REG   =0x04;
byte ACTION=0x05;
byte RESET =0x06;
byte SYNC  =0x83;
byte BEGIN =0xff;
int incomingByte = 0;


//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Setup Function
//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void setup () {
  pinMode(RTSpin, OUTPUT);
  Serial.begin(57600);
  Serial1.begin(57600);

  byte notchecksum;
  digitalWrite(RTSpin,HIGH);
  delay (5);
  notchecksum=~(0x01 + 0x02 + ping);
  Serial1.write(BEGIN);
  Serial1.write(BEGIN);
  Serial1.write(0x01);
  Serial1.write(0x02);
  Serial1.write(ping);
  Serial1.write(notchecksum);
  Serial1.write(0);
  digitalWrite(RTSpin,LOW);
  // send data only when you receive data:
while (Serial.available() < 0) {
     incomingByte = Serial1.read();
     Serial.print(incomingByte,HEX);
     delay(1000);
  }
}

// Main function
void loop() 
{
  //This is program to send data to servo

}

I am expecting to get a data of 0XFF 0XFF 0X01 0X02 0X00 0XFC but instead the serial monitor give me back the data 0XFF 0XFF 0XFF 0XFF 0XFF 0XFF.

Can anyone advice me what is wrong with my code?

Thank you

Moderator edit: CODE TAGS added

while (Serial.available() < 0) {
     incomingByte = Serial1.read();

Two things here.
First, Serial.available only returns zero or positive values.
Second, why check one port to see if it has data available, and then read the data from another?

Thanks.

My mistake.

Actually What I want to do is :

  1. Send ping command to dynamixel
  2. Obtain the return packet from dynamixel.

Do you have any code to obtain the return packet from dynamixel?. So far I do not able to obtain any return packet.

Have you corrected your code?
What is it doing now?

(Sorry, I don't have this device, so I can't try it for myself).

Yup. I have try to correct it. The result is still the same. I only obtain the data FFFFFF from the motor.

Anyone have try to connect the dynamixel and arduino with simple programming before?

I only obtain the data FFFFFF from the motor.

That suggest to me that you haven't fixed your code, and that you're reading -1 == "No serial data available" from your port.
Please post your code.

AWOL:

I only obtain the data FFFFFF from the motor.

That suggest to me that you haven't fixed your code, and that you're reading -1 == "No serial data available" from your port.
Please post your code.

Hi AWOL,

I fixed the code already.

//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Initial condition
//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

const int RTS = 4;   //1= transmit, 0 =receive
byte ping  =0x01;
byte READ  =0x02;
byte WRITE =0x03;
byte REG   =0x04;
byte ACTION=0x05;
byte RESET =0x06;
byte SYNC  =0x83;
byte BEGIN =0xff;
int incomingByte = 0;


//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Setup Function
//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void setup () {
  pinMode(RTS, OUTPUT);
  Serial.begin(57600);
  Serial1.begin(57600);

}

// Main function
void loop() 
{
  byte notchecksum;
  byte motor_ID=0x01;
  byte length=0x02;
  digitalWrite(RTS,HIGH);
  delay (5);
  notchecksum=~(motor_ID + length + ping);
  Serial1.write(BEGIN);
  Serial1.write(BEGIN);
  Serial1.write(motor_ID);
  Serial1.write(length);
  Serial1.write(ping);
  Serial1.write(notchecksum);
  digitalWrite(RTS,LOW);
  // send data only when you receive data:
while (Serial1.available() == 0) 
{
     incomingByte = Serial1.read();
  }
  incomingByte = Serial1.read();
  Serial.print(Serial1.available(),HEX);
  delay(1000);
}//This is program to send data to servo

Now, is the serial monitor does not give any display. I suspect that it keep stuck inside the WHILE loop.
Now, I am wondering if my Dynamixel motor does not send any data or, My 485 breakout circuit does not send me any data.
Do you have any idea?

Thanks

while (Serial1.available() == 0) 
{
     incomingByte = Serial1.read();
  }

So, while there is no data available, read the data that isn't there?

Yup.
Just in case that I miss the data transmitted.
However, I do not get any result out. As I expected when the serial1 received the data, it should go out of the loop and print the value that is stored at "inbyte"

Just in case that I miss the data transmitted.

I'd say you're pretty much guaranteeing that you will miss data, in very nasty, creative ways.

Think.

Test if there's a character available.
An interrupt happens to occur before the "read", and character is put in the receive buffer.
Interrupt returns, and you read the character, 'cos that's what your loop does.
Test to see if there's a character available.
Oops.

Don't do anything in the "while" loop.

Still not working

=( =( =( =(

Does it got relation with the baud speed that I set up?
Does Dynamixel need higher baud rate to communicate?

Still not working

Still not seeing any code.