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.
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.
The servo powers up properly, as I can see the LED blink when it receives power.
I know that the servo functions properly, as I can plug it into a CM-700 and control it through the manager
Using the DynamixelSerial1 library and code below.
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.
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;
}
}