Pages: [1]   Go Down
Author Topic: Need help in connecting Arduino with Dynamixel RX-64  (Read 1830 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:
//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 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
« Last Edit: January 16, 2013, 04:38:31 am by AWOL » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25756
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25756
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25756
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Code:
//___________________________________________________________________
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// 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
« Last Edit: January 20, 2013, 10:02:06 pm by fr3dd3v1l » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25756
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
while (Serial1.available() == 0)
{
     incomingByte = Serial1.read();
  }
So, while there is no data available, read the data that isn't there?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25756
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still not working

 smiley-cry smiley-cry smiley-cry smiley-cry

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25756
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Still not working
Still not seeing any code.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: