Skip to content

Commit d49c0fe

Browse files
author
Kei
authored
Merge pull request #24 from ROBOTIS-GIT/update_for_#23
PR associated with #23.
2 parents a688da3 + 7e29368 commit d49c0fe

File tree

28 files changed

+556
-73
lines changed

28 files changed

+556
-73
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
# Dynamixel2Arduino [![Build Status](https://travis-ci.org/ROBOTIS-GIT/Dynamixel2Arduino.svg?branch=master)](https://travis-ci.org/ROBOTIS-GIT/Dynamixel2Arduino/branches)
22

3+
## Serial and Direction Pin definitions by board
4+
- The examples default to pins based on DynamixelShield. Therefore, when using hardware other than DynamixelShield (eg OpenCM9.04, OpenCR, Custom DXL boards), you need to change the Serial and Direction Pin.
5+
- We provide the information below to make it easier to define Serial and Direction pins for specific hardware.
6+
7+
|Board Name|Serial|Direction Pin|Note|
8+
|:-:|:-:|:-:|:-:|
9+
|OpenCM9.04|Serial1|28|because of the OpenCM 9.04 driver code, you must call Serial1.setDxlMode(true); before dxl.begin();.|
10+
|OpenCM9.04 EXP|Serial3|22||
11+
|OpenCR|Serial3|84|For OpenCR, there is a DXL Power Enable pin, so you must initialize and control it. ([Reference link](https://github.com/ROBOTIS-GIT/OpenCR/blob/master/arduino/opencr_arduino/opencr/libraries/DynamixelSDK/src/dynamixel_sdk/port_handler_arduino.cpp#L78))|
12+
13+
314
## How to add new DYNAMIXEL model.
415
- For the convenience of the user, Dynamixel2Arduino API hardcodes some information in the control table and stores it in flash.
516
- To do this, you need to add code to some files. In this regard, please refer to [PR#3](https://github.com/ROBOTIS-GIT/Dynamixel2Arduino/pull/3) and [PR#7](https://github.com/ROBOTIS-GIT/Dynamixel2Arduino/pull/7)
617

18+
## How to create custom PortHandler Class
19+
- Please refer to [port_handler.h](https://github.com/ROBOTIS-GIT/Dynamixel2Arduino/blob/master/src/utility/port_handler.h)
20+
- Create a new class by inheriting PortHandler as public. (Like SerialPortHandler and USBSerialPortHandler)
721

822
## TODO
923
- Separation of protocol codes (protocol, packet handler)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*******************************************************************************
2+
* Copyright 2016 ROBOTIS CO., LTD.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
17+
#include <Dynamixel2Arduino.h>
18+
19+
// Please modify it to suit your hardware.
20+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) // When using DynamixelShield
21+
#include <SoftwareSerial.h>
22+
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
23+
#define DXL_SERIAL Serial
24+
#define DEBUG_SERIAL soft_serial
25+
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
26+
#elif ARDUINO_OpenCM904 // Official ROBOTIS board with DXL circuit.
27+
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (Serial1 for the DXL port on the OpenCM 9.04 board)
28+
#define DEBUG_SERIAL Serial
29+
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (28 for the DXL port on the OpenCM 9.04 board)
30+
#elif ARDUINO_OpenCR // Official ROBOTIS board with DXL circuit.
31+
// For OpenCR, there is a DXL Power Enable pin, so you must initialize and control it.
32+
// Reference link : https://github.com/ROBOTIS-GIT/OpenCR/blob/master/arduino/opencr_arduino/opencr/libraries/DynamixelSDK/src/dynamixel_sdk/port_handler_arduino.cpp#L78
33+
#define DXL_SERIAL Serial3
34+
#define DEBUG_SERIAL Serial
35+
const uint8_t DXL_DIR_PIN = 84; //OpenCM9.04 EXP Board's DIR PIN. (To use the DXL port on the OpenCM 9.04 board, you must use 28 for DIR PIN.)
36+
#else // When using DynamixelShield
37+
#define DXL_SERIAL Serial1
38+
#define DEBUG_SERIAL Serial
39+
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
40+
#endif
41+
42+
class NewSerialPortHandler : public DYNAMIXEL::SerialPortHandler
43+
{
44+
public:
45+
NewSerialPortHandler(HardwareSerial& port, const int dir_pin = -1)
46+
: SerialPortHandler(port, dir_pin), port_(port), dir_pin_(dir_pin)
47+
{}
48+
49+
virtual size_t write(uint8_t c) override
50+
{
51+
size_t ret = 0;
52+
digitalWrite(DXL_DIR_PIN, HIGH);
53+
while(digitalRead(DXL_DIR_PIN) != HIGH);
54+
55+
ret = port_.write(c);
56+
57+
port_.flush();
58+
digitalWrite(DXL_DIR_PIN, LOW);
59+
while(digitalRead(DXL_DIR_PIN) != LOW);
60+
61+
return ret;
62+
}
63+
64+
virtual size_t write(uint8_t *buf, size_t len) override
65+
{
66+
size_t ret;
67+
digitalWrite(DXL_DIR_PIN, HIGH);
68+
while(digitalRead(DXL_DIR_PIN) != HIGH);
69+
70+
ret = port_.write(buf, len);
71+
72+
port_.flush();
73+
digitalWrite(DXL_DIR_PIN, LOW);
74+
while(digitalRead(DXL_DIR_PIN) != LOW);
75+
76+
return ret;
77+
}
78+
79+
private:
80+
HardwareSerial& port_;
81+
const int dir_pin_;
82+
};
83+
84+
const uint8_t DXL_ID = 1;
85+
const float DXL_PROTOCOL_VERSION = 2.0;
86+
87+
Dynamixel2Arduino dxl;
88+
NewSerialPortHandler dxl_port(DXL_SERIAL, DXL_DIR_PIN);
89+
90+
91+
void setup() {
92+
// put your setup code here, to run once:
93+
94+
// Use Serial to debug.
95+
DEBUG_SERIAL.begin(115200);
96+
97+
// Set Port instance
98+
dxl.setPort(dxl_port);
99+
// Set Port baudrate to 57600bps. This has to match with DYNAMIXEL baudrate.
100+
dxl.begin(57600);
101+
// Set Port Protocol Version. This has to match with DYNAMIXEL protocol version.
102+
dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
103+
}
104+
105+
void loop() {
106+
// put your main code here, to run repeatedly:
107+
108+
DEBUG_SERIAL.print("PROTOCOL ");
109+
DEBUG_SERIAL.print(DXL_PROTOCOL_VERSION, 1);
110+
DEBUG_SERIAL.print(", ID ");
111+
DEBUG_SERIAL.print(DXL_ID);
112+
DEBUG_SERIAL.print(": ");
113+
if(dxl.ping(DXL_ID) == true){
114+
DEBUG_SERIAL.print("ping succeeded!");
115+
DEBUG_SERIAL.print(", Model Number: ");
116+
DEBUG_SERIAL.println(dxl.getModelNumber(DXL_ID));
117+
}else{
118+
DEBUG_SERIAL.println("ping failed!");
119+
}
120+
delay(500);
121+
}
122+
123+
124+

examples/advanced/bulk_read_write_raw/bulk_read_write_raw.ino

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@
1616

1717
#include <Dynamixel2Arduino.h>
1818

19-
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560)
19+
// Please modify it to suit your hardware.
20+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) // When using DynamixelShield
2021
#include <SoftwareSerial.h>
2122
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
2223
#define DXL_SERIAL Serial
2324
#define DEBUG_SERIAL soft_serial
2425
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
25-
#else
26+
#elif ARDUINO_OpenCM904 // Official ROBOTIS board with DXL circuit.
27+
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (Serial1 for the DXL port on the OpenCM 9.04 board)
28+
#define DEBUG_SERIAL Serial
29+
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (28 for the DXL port on the OpenCM 9.04 board)
30+
#elif ARDUINO_OpenCR // Official ROBOTIS board with DXL circuit.
31+
// For OpenCR, there is a DXL Power Enable pin, so you must initialize and control it.
32+
// Reference link : https://github.com/ROBOTIS-GIT/OpenCR/blob/master/arduino/opencr_arduino/opencr/libraries/DynamixelSDK/src/dynamixel_sdk/port_handler_arduino.cpp#L78
33+
#define DXL_SERIAL Serial3
34+
#define DEBUG_SERIAL Serial
35+
const uint8_t DXL_DIR_PIN = 84; //OpenCM9.04 EXP Board's DIR PIN. (To use the DXL port on the OpenCM 9.04 board, you must use 28 for DIR PIN.)
36+
#else // When using DynamixelShield
2637
#define DXL_SERIAL Serial1
2738
#define DEBUG_SERIAL Serial
2839
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN

examples/advanced/operating_mode_advanced/operating_mode_advanced.ino

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@
1616

1717
#include <Dynamixel2Arduino.h>
1818

19-
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560)
19+
// Please modify it to suit your hardware.
20+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) // When using DynamixelShield
2021
#include <SoftwareSerial.h>
2122
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
2223
#define DXL_SERIAL Serial
2324
#define DEBUG_SERIAL soft_serial
2425
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
25-
#else
26+
#elif ARDUINO_OpenCM904 // Official ROBOTIS board with DXL circuit.
27+
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (Serial1 for the DXL port on the OpenCM 9.04 board)
28+
#define DEBUG_SERIAL Serial
29+
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (28 for the DXL port on the OpenCM 9.04 board)
30+
#elif ARDUINO_OpenCR // Official ROBOTIS board with DXL circuit.
31+
// For OpenCR, there is a DXL Power Enable pin, so you must initialize and control it.
32+
// Reference link : https://github.com/ROBOTIS-GIT/OpenCR/blob/master/arduino/opencr_arduino/opencr/libraries/DynamixelSDK/src/dynamixel_sdk/port_handler_arduino.cpp#L78
33+
#define DXL_SERIAL Serial3
34+
#define DEBUG_SERIAL Serial
35+
const uint8_t DXL_DIR_PIN = 84; //OpenCM9.04 EXP Board's DIR PIN. (To use the DXL port on the OpenCM 9.04 board, you must use 28 for DIR PIN.)
36+
#else // When using DynamixelShield
2637
#define DXL_SERIAL Serial1
2738
#define DEBUG_SERIAL Serial
2839
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN

examples/advanced/read_write_ControlTableItem/read_write_ControlTableItem.ino

+15-13
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,27 @@
115115
EXTERNAL_PORT_DATA_4,
116116
*/
117117

118-
119-
#ifdef ARDUINO_AVR_UNO
118+
// Please modify it to suit your hardware.
119+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) // When using DynamixelShield
120120
#include <SoftwareSerial.h>
121-
SoftwareSerial soft_serial(7, 8); //RX,TX
121+
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
122122
#define DXL_SERIAL Serial
123123
#define DEBUG_SERIAL soft_serial
124-
const uint8_t DXL_DIR_PIN = 2; //DYNAMIXEL Shield
125-
#elif ARDUINO_AVR_MEGA2560
126-
#define DXL_SERIAL Serial
127-
#define DEBUG_SERIAL Serial1
128-
const uint8_t DXL_DIR_PIN = 2; //DYNAMIXEL Shield
129-
#elif BOARD_OpenCM904
130-
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (To use the DXL port on the OpenCM 9.04 board, you must use Serial1 for Serial. And because of the OpenCM 9.04 driver code, you must call Serial1.setDxlMode(true); before dxl.begin();.)
124+
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
125+
#elif ARDUINO_OpenCM904 // Official ROBOTIS board with DXL circuit.
126+
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (Serial1 for the DXL port on the OpenCM 9.04 board)
127+
#define DEBUG_SERIAL Serial
128+
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (28 for the DXL port on the OpenCM 9.04 board)
129+
#elif ARDUINO_OpenCR // Official ROBOTIS board with DXL circuit.
130+
// For OpenCR, there is a DXL Power Enable pin, so you must initialize and control it.
131+
// Reference link : https://github.com/ROBOTIS-GIT/OpenCR/blob/master/arduino/opencr_arduino/opencr/libraries/DynamixelSDK/src/dynamixel_sdk/port_handler_arduino.cpp#L78
132+
#define DXL_SERIAL Serial3
131133
#define DEBUG_SERIAL Serial
132-
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (To use the DXL port on the OpenCM 9.04 board, you must use 28 for DIR PIN.)
133-
#else
134+
const uint8_t DXL_DIR_PIN = 84; //OpenCM9.04 EXP Board's DIR PIN. (To use the DXL port on the OpenCM 9.04 board, you must use 28 for DIR PIN.)
135+
#else // When using DynamixelShield
134136
#define DXL_SERIAL Serial1
135137
#define DEBUG_SERIAL Serial
136-
const uint8_t DXL_DIR_PIN = 2; //DYNAMIXEL Shield
138+
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
137139
#endif
138140

139141
const uint8_t DXL_ID = 1;

examples/advanced/slave/slave.ino

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@
1616

1717
#include <Dynamixel2Arduino.h>
1818

19-
// The following definitions are examples when using the DYNAMIXEL Shield.
2019
// Please modify it to suit your hardware.
21-
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560)
20+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) // When using DynamixelShield
2221
#include <SoftwareSerial.h>
2322
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
2423
#define DXL_SERIAL Serial
2524
#define DEBUG_SERIAL soft_serial
2625
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
27-
#else
26+
#elif ARDUINO_OpenCM904 // Official ROBOTIS board with DXL circuit.
27+
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (Serial1 for the DXL port on the OpenCM 9.04 board)
28+
#define DEBUG_SERIAL Serial
29+
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (28 for the DXL port on the OpenCM 9.04 board)
30+
#elif ARDUINO_OpenCR // Official ROBOTIS board with DXL circuit.
31+
// For OpenCR, there is a DXL Power Enable pin, so you must initialize and control it.
32+
// Reference link : https://github.com/ROBOTIS-GIT/OpenCR/blob/master/arduino/opencr_arduino/opencr/libraries/DynamixelSDK/src/dynamixel_sdk/port_handler_arduino.cpp#L78
33+
#define DXL_SERIAL Serial3
34+
#define DEBUG_SERIAL Serial
35+
const uint8_t DXL_DIR_PIN = 84; //OpenCM9.04 EXP Board's DIR PIN. (To use the DXL port on the OpenCM 9.04 board, you must use 28 for DIR PIN.)
36+
#else // When using DynamixelShield
2837
#define DXL_SERIAL Serial1
2938
#define DEBUG_SERIAL Serial
3039
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN

examples/advanced/slave_callback/slave_callback.ino

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@
1616

1717
#include <Dynamixel2Arduino.h>
1818

19-
// The following definitions are examples when using the DYNAMIXEL Shield.
2019
// Please modify it to suit your hardware.
21-
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560)
20+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) // When using DynamixelShield
2221
#include <SoftwareSerial.h>
2322
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
2423
#define DXL_SERIAL Serial
2524
#define DEBUG_SERIAL soft_serial
2625
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
27-
#else
26+
#elif ARDUINO_OpenCM904 // Official ROBOTIS board with DXL circuit.
27+
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (Serial1 for the DXL port on the OpenCM 9.04 board)
28+
#define DEBUG_SERIAL Serial
29+
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (28 for the DXL port on the OpenCM 9.04 board)
30+
#elif ARDUINO_OpenCR // Official ROBOTIS board with DXL circuit.
31+
// For OpenCR, there is a DXL Power Enable pin, so you must initialize and control it.
32+
// Reference link : https://github.com/ROBOTIS-GIT/OpenCR/blob/master/arduino/opencr_arduino/opencr/libraries/DynamixelSDK/src/dynamixel_sdk/port_handler_arduino.cpp#L78
33+
#define DXL_SERIAL Serial3
34+
#define DEBUG_SERIAL Serial
35+
const uint8_t DXL_DIR_PIN = 84; //OpenCM9.04 EXP Board's DIR PIN. (To use the DXL port on the OpenCM 9.04 board, you must use 28 for DIR PIN.)
36+
#else // When using DynamixelShield
2837
#define DXL_SERIAL Serial1
2938
#define DEBUG_SERIAL Serial
3039
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN

examples/advanced/sync_bulk_raw/sync_bulk_raw.ino

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@
1616

1717
#include <Dynamixel2Arduino.h>
1818

19-
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560)
19+
// Please modify it to suit your hardware.
20+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) // When using DynamixelShield
2021
#include <SoftwareSerial.h>
2122
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
2223
#define DXL_SERIAL Serial
2324
#define DEBUG_SERIAL soft_serial
2425
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
25-
#else
26+
#elif ARDUINO_OpenCM904 // Official ROBOTIS board with DXL circuit.
27+
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (Serial1 for the DXL port on the OpenCM 9.04 board)
28+
#define DEBUG_SERIAL Serial
29+
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (28 for the DXL port on the OpenCM 9.04 board)
30+
#elif ARDUINO_OpenCR // Official ROBOTIS board with DXL circuit.
31+
// For OpenCR, there is a DXL Power Enable pin, so you must initialize and control it.
32+
// Reference link : https://github.com/ROBOTIS-GIT/OpenCR/blob/master/arduino/opencr_arduino/opencr/libraries/DynamixelSDK/src/dynamixel_sdk/port_handler_arduino.cpp#L78
33+
#define DXL_SERIAL Serial3
34+
#define DEBUG_SERIAL Serial
35+
const uint8_t DXL_DIR_PIN = 84; //OpenCM9.04 EXP Board's DIR PIN. (To use the DXL port on the OpenCM 9.04 board, you must use 28 for DIR PIN.)
36+
#else // When using DynamixelShield
2637
#define DXL_SERIAL Serial1
2738
#define DEBUG_SERIAL Serial
2839
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN

examples/advanced/sync_read_write_raw/sync_read_write_raw.ino

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@
1616

1717
#include <Dynamixel2Arduino.h>
1818

19-
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560)
19+
// Please modify it to suit your hardware.
20+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) // When using DynamixelShield
2021
#include <SoftwareSerial.h>
2122
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
2223
#define DXL_SERIAL Serial
2324
#define DEBUG_SERIAL soft_serial
2425
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
25-
#else
26+
#elif ARDUINO_OpenCM904 // Official ROBOTIS board with DXL circuit.
27+
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (Serial1 for the DXL port on the OpenCM 9.04 board)
28+
#define DEBUG_SERIAL Serial
29+
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (28 for the DXL port on the OpenCM 9.04 board)
30+
#elif ARDUINO_OpenCR // Official ROBOTIS board with DXL circuit.
31+
// For OpenCR, there is a DXL Power Enable pin, so you must initialize and control it.
32+
// Reference link : https://github.com/ROBOTIS-GIT/OpenCR/blob/master/arduino/opencr_arduino/opencr/libraries/DynamixelSDK/src/dynamixel_sdk/port_handler_arduino.cpp#L78
33+
#define DXL_SERIAL Serial3
34+
#define DEBUG_SERIAL Serial
35+
const uint8_t DXL_DIR_PIN = 84; //OpenCM9.04 EXP Board's DIR PIN. (To use the DXL port on the OpenCM 9.04 board, you must use 28 for DIR PIN.)
36+
#else // When using DynamixelShield
2637
#define DXL_SERIAL Serial1
2738
#define DEBUG_SERIAL Serial
2839
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN

examples/basic/baudrate/baudrate.ino

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@
1616

1717
#include <Dynamixel2Arduino.h>
1818

19-
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560)
19+
// Please modify it to suit your hardware.
20+
#if defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_MEGA2560) // When using DynamixelShield
2021
#include <SoftwareSerial.h>
2122
SoftwareSerial soft_serial(7, 8); // DYNAMIXELShield UART RX/TX
2223
#define DXL_SERIAL Serial
2324
#define DEBUG_SERIAL soft_serial
2425
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
25-
#else
26+
#elif ARDUINO_OpenCM904 // Official ROBOTIS board with DXL circuit.
27+
#define DXL_SERIAL Serial3 //OpenCM9.04 EXP Board's DXL port Serial. (Serial1 for the DXL port on the OpenCM 9.04 board)
28+
#define DEBUG_SERIAL Serial
29+
const uint8_t DXL_DIR_PIN = 22; //OpenCM9.04 EXP Board's DIR PIN. (28 for the DXL port on the OpenCM 9.04 board)
30+
#elif ARDUINO_OpenCR // Official ROBOTIS board with DXL circuit.
31+
// For OpenCR, there is a DXL Power Enable pin, so you must initialize and control it.
32+
// Reference link : https://github.com/ROBOTIS-GIT/OpenCR/blob/master/arduino/opencr_arduino/opencr/libraries/DynamixelSDK/src/dynamixel_sdk/port_handler_arduino.cpp#L78
33+
#define DXL_SERIAL Serial3
34+
#define DEBUG_SERIAL Serial
35+
const uint8_t DXL_DIR_PIN = 84; //OpenCM9.04 EXP Board's DIR PIN. (To use the DXL port on the OpenCM 9.04 board, you must use 28 for DIR PIN.)
36+
#else // When using DynamixelShield
2637
#define DXL_SERIAL Serial1
2738
#define DEBUG_SERIAL Serial
2839
const uint8_t DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN

0 commit comments

Comments
 (0)