What I'm attempting to do, is to get a firm grasp on the servo's communication protocol. To keep things simple I'm starting with an Arduino Mega and I'm sending the data through an ST485 RS-485 converter chip. I'm having some difficulty when trying to interface with a Dynamixel MX-28
For the controls, I'm using an Arduino Mega and an RS-485 converter, connected as follows. I've also attached my test sketch to this post. All I'm trying to do is to make the LED blink
Arduino --- ST485
Tx3(D14) --- Data In
Rx3(D15) --- Data out
D7 ----------- !(Receive Enable) / Transmit Enable
I have verified that the MX-28 is working using RoboPlus. I have verified the RS-485 output using my scope but it's still not working right.
Code:
//*************************************************************
// TITLE:
// Dynamixel RS-485 Test Program
//
// SCOPE:
// This test program is intended to demonstrate the control
// of a Dynamixel servo over RS-485. The TTL to RS-485
// conversion is handled by a ST485 transciever on an RS-485
// breakout board.
//
// TERMINATIONS:
//
// Arduino RS-485 Breakout
// D14 - TTL Tx DI
// D15 - TTL Rx R0
// D7 - RS485-EN DE/RE
//*************************************************************
// *******************************
// DEFINES
// *******************************
#define RS485_EN 7 // Hardware location of enable line
byte startAddress;
byte servoID = 0x01; // 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;
unsigned char instruction = 0x03;
startAddress = 0x19; // Turning on led
checksum_ACK = servoID + length + instruction + 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(instruction); // 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(15); // 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);
//Serial3.begin(115200);
pinMode(RS485_EN, OUTPUT);
delay(3000);
}
//*************************************************************
// FUNCTION: loop
// RETURNS: Nothing
// DESCRIPTION: Our main program loop
//*************************************************************
void loop() {
//Transmission section
delay(1);
if (i%2 ==0){
activateServos(servoID, ledOn);
delay(2000);
} else {
activateServos(servoID, ledOff);
delay(2000);
}
i++;
if (i>1000){
i=1;
}
}
Bookmarks