Offline
Newbie
Karma: 0
Posts: 9
|
 |
« on: January 16, 2013, 04:00:41 am » |
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
|
|
|
|
« Last Edit: January 16, 2013, 04:38:31 am by AWOL »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: January 16, 2013, 04:37:41 am » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #2 on: January 16, 2013, 05:07:03 am » |
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
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: January 16, 2013, 05:27:49 am » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #4 on: January 17, 2013, 07:37:02 pm » |
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
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #5 on: January 18, 2013, 02:39:48 am » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #6 on: January 20, 2013, 09:44:27 pm » |
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
|
|
|
|
« Last Edit: January 20, 2013, 10:02:06 pm by fr3dd3v1l »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #7 on: January 21, 2013, 03:04:59 am » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #8 on: January 21, 2013, 03:30:39 am » |
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
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #9 on: January 21, 2013, 03:35:21 am » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #10 on: January 21, 2013, 05:37:21 am » |
Still not working  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
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #11 on: January 21, 2013, 05:45:02 am » |
Still not working Still not seeing any code.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|