Communication problem

hello,
I am using XC 430-W240 with Arduino uno and DYNAMIXEL shield. And I am uploading codes using Arduino IDE. I am feeding the Arduino using 12V DC Adapter.

when I connected the motor to U2D2 Connector, I Could control it fully using DYNAMIXEL WIZARD 2.0. But when I use arduino IDE I cannot run even a simple code like the code below. I have checked the power, cables, shield, and Arduino uno. they are all working properly.
Can you help me please?

#include <DynamixelShield.h>

#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560)
#include <SoftwareSerial.h>
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
#define DEBUG_SERIAL soft_serial
#elif defined(ARDUINO_SAM_DUE) || defined(ARDUINO_SAM_ZERO)
#define DEBUG_SERIAL SerialUSB
#else
#define DEBUG_SERIAL Serial
#endif

//Please see eManual Control Table section of your DYNAMIXEL.
//This example is written for DYNAMIXEL X series(excluding XL-320)
#define OPERATING_MODE_ADDR 11
#define OPERATING_MODE_ADDR_LEN 1
#define TORQUE_ENABLE_ADDR 64
#define TORQUE_ENABLE_ADDR_LEN 1
#define LED_ADDR 65
#define LED_ADDR_LEN 1
#define GOAL_POSITION_ADDR 116
#define GOAL_POSITION_ADDR_LEN 4
#define PRESENT_POSITION_ADDR 132
#define PRESENT_POSITION_ADDR_LEN 4
#define POSITION_CONTROL_MODE 3
#define TIMEOUT 10 //default communication timeout 10ms

uint8_t turn_on = 1;
uint8_t turn_off = 0;

const uint8_t DXL_ID = 1;
const float DXL_PROTOCOL_VERSION = 2.0;

uint8_t operatingMode = POSITION_CONTROL_MODE;
uint32_t goalPosition1 = 512;
uint32_t goalPosition2 = 2048;

DynamixelShield dxl;

void setup() {
// put your setup code here, to run once:

// For Uno, Nano, Mini, and Mega, use UART port of DYNAMIXEL Shield to debug.
DEBUG_SERIAL.begin(115200); //Set debugging port baudrate to 115200bps
while(!DEBUG_SERIAL); //Wait until the serial port for terminal is opened

// Set Port baudrate to 57600bps. This has to match with DYNAMIXEL baudrate.
dxl.begin(57600);
// Set Port Protocol Version. This has to match with DYNAMIXEL protocol version.
dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);

// Turn off torque when configuring items in EEPROM area
if(dxl.write(DXL_ID, TORQUE_ENABLE_ADDR, (uint8_t*)&turn_off , TORQUE_ENABLE_ADDR_LEN, TIMEOUT))
DEBUG_SERIAL.println(“DYNAMIXEL Torque off”);
else
DEBUG_SERIAL.println(“Error: Torque off failed”);

// Set Operating Mode
if(dxl.write(DXL_ID, OPERATING_MODE_ADDR, (uint8_t*)&operatingMode, OPERATING_MODE_ADDR_LEN, TIMEOUT))
DEBUG_SERIAL.println(“Set operating mode”);
else
DEBUG_SERIAL.println(“Error: Set operating mode failed”);

// Turn on torque
if(dxl.write(DXL_ID, TORQUE_ENABLE_ADDR, (uint8_t*)&turn_on, TORQUE_ENABLE_ADDR_LEN, TIMEOUT))
DEBUG_SERIAL.println(“Torque on”);
else
DEBUG_SERIAL.println(“Error: Torque on failed”);
}

void loop() {
// put your main code here, to run repeatedly:

// LED On
DEBUG_SERIAL.println(“LED ON”);
dxl.write(DXL_ID, LED_ADDR, (uint8_t*)&turn_on, LED_ADDR_LEN, TIMEOUT);
delay(500);

// Please refer to e-Manual(DYNAMIXEL Shield) for available range of value.
// Set Goal Position
DEBUG_SERIAL.print("Goal Position : ");
DEBUG_SERIAL.println(goalPosition1);
dxl.write(DXL_ID, GOAL_POSITION_ADDR, (uint8_t*)&goalPosition1, GOAL_POSITION_ADDR_LEN, TIMEOUT);
delay(1000);

// LED Off
DEBUG_SERIAL.println(“LED OFF”);
dxl.write(DXL_ID, LED_ADDR, (uint8_t*)&turn_off, LED_ADDR_LEN, TIMEOUT);
delay(500);

// Set Goal Position
DEBUG_SERIAL.print("Goal Position : ");
DEBUG_SERIAL.println(goalPosition2);
dxl.write(DXL_ID, GOAL_POSITION_ADDR, (uint8_t*)&goalPosition2, GOAL_POSITION_ADDR_LEN, TIMEOUT);
delay(1000);
}

Hi @Mohammad

Arduino Uno has only 1 serial which cannot be used for both USB upload / debug and DYNAMIXEL communication at the same time.
In order to control DYNAMIXEL with Uno + DYNAMIXEL Shield, please make sure to set the switch to DYNAMIXEL side after uploading the example.

For more information, please refer to the eManual below.

Thanks!

thank you so much. I am also using LN-101 for serial communication. After uploading the code I switch the port to open the serial monitor on LN-101. Furthermore, some codes do not need any kind of serial communication like the code below :
#include <DynamixelShield.h>

const uint8_t DXL_ID = 1;
const float DXL_PROTOCOL_VERSION = 2.0;

DynamixelShield dxl;

//This namespace is required to use Control table item names
using namespace ControlTableItem;

void setup() {
// put your setup code here, to run once:

// Set Port baudrate to 57600bps. This has to match with DYNAMIXEL baudrate.
dxl.begin(57600);
// Set Port Protocol Version. This has to match with DYNAMIXEL protocol version.
dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
// Get DYNAMIXEL information
dxl.ping(DXL_ID);
}

void loop() {
// put your main code here, to run repeatedly:

// Turn on the output Torque.
dxl.torqueOn(DXL_ID);
delay(2000);

// Turn off the output Torque.
dxl.torqueOff(DXL_ID);
delay(2000);
}

This also didn’t work.

I have tried so many codes. Serial monitor always shows the right messages like Led on Led off… but without any motion or actual turning on/off for the led.

can someone help me please?

The example code that you have posted does not include a definition for the DYNAMIXEL’s serial communication port, or for the serial communication direction pin as included in the DYNAMIXEL2Arduino example code.

Until you are very familiar with what exactly is and is not required for DYNAMIXEL control using your specific hardware setup, I recommend copying the entire definition set from the DYNAMIXEL2Arduino programming examples.

okay thank you so much, how can I know what exactly is and is not required for my DYNAMIXEL. how can I reach for these information. can you help me please with link or explanation.

Hmm… if you have correctly included the dynamixelshield.h file, it’ll basically configure necessary serial port and pins.
Could you check if you have the latest version of dynamixel2arduino (0.6.1) and dynamixelshield (0.2.6) library installed on your Arduino IDE?
You can find them from [Sketch] > [Include Library] > [Manage Libraries] and search for dynamixel2arduino and dynamixelshield.