/
baudrate.ino
80 lines (67 loc) · 2.68 KB
/
baudrate.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*******************************************************************************
* Copyright 2016 ROBOTIS CO., LTD.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#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
const uint8_t DXL_ID = 1;
const float DXL_PROTOCOL_VERSION = 2.0;
uint32_t BAUDRATE = 57600;
uint32_t NEW_BAUDRATE = 1000000; //1Mbsp
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:
// For Uno, Nano, Mini, and Mega, use UART port of DYNAMIXEL Shield to debug.
DEBUG_SERIAL.begin(115200);
// Set Port baudrate to 57600bps. This has to match with DYNAMIXEL baudrate.
dxl.begin(BAUDRATE);
// Set Port Protocol Version. This has to match with DYNAMIXEL protocol version.
dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
DEBUG_SERIAL.print("PROTOCOL ");
DEBUG_SERIAL.print(DXL_PROTOCOL_VERSION, 1);
DEBUG_SERIAL.print(", ID ");
DEBUG_SERIAL.print(DXL_ID);
DEBUG_SERIAL.print(": ");
if(dxl.ping(DXL_ID) == true) {
DEBUG_SERIAL.print("ping succeeded!");
DEBUG_SERIAL.print(", Baudrate: ");
DEBUG_SERIAL.println(BAUDRATE);
// Turn off torque when configuring items in EEPROM area
dxl.torqueOff(DXL_ID);
// Set a new baudrate(1Mbps) for DYNAMIXEL
dxl.setBaudrate(DXL_ID, NEW_BAUDRATE);
DEBUG_SERIAL.println("Baudrate has been successfully changed to 1Mbps");
// Change to the new baudrate for communication.
dxl.begin(NEW_BAUDRATE);
// Change back to the initial baudrate
dxl.setBaudrate(DXL_ID, BAUDRATE);
DEBUG_SERIAL.println("Baudrate has been successfully changed back to initial baudrate");
}
else{
DEBUG_SERIAL.println("ping failed!");
}
}
void loop() {
// put your main code here, to run repeatedly:
}