ROBOTIS-GIT / Dynamixel2Arduino

DYNAMIXEL protocol library for Arduino
Apache License 2.0
88 stars 55 forks source link

Teensy 3.2 with RS485 Breakout and MX-28AR #113

Open lyehezkel opened 2 years ago

lyehezkel commented 2 years ago

Hello, I am having trouble with connecting the following together and getting data from my mx-28ar DYNAMIXEL. i have a teensy 3.2, which is connected to the computer through micro-usb. the teensy is connected to my RS485 Breakout through 4 pins: teensy 3.2 <---> RS485:

the RS485 is connected to the MX-28AR through 3 pins: RS485 <---> MX-28AR

and the mx-28ar is connected to a 12V power supply through smps2dynamixel

My problem is that i cant get any information from the mx-28ar with the teensy, i tried to use the "ping" example from the arduino2dynamixel library and in my monitor i get the "error 3" (which i dont understand at the moment). my mx-28ar is set to 57600 baud and his id is 3, protocol 2.0 - Double checked it via DYNAMIXEL wizard I'm using the following code:


#include <Dynamixel2Arduino.h>
//#include <SoftwareSerial.h>
  //SoftwareSerial soft_serial(9, 10); // DYNAMIXELShield UART RX/TX
  #define DXL_SERIAL   Serial2
  const int DXL_DIR_PIN = 2; // DYNAMIXEL Shield DIR PIN
 #define DEBUG_SERIAL Serial

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

Dynamixel2Arduino dxl(DXL_SERIAL, DXL_DIR_PIN);

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

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

  // Use Serial to debug.
  DEBUG_SERIAL.begin(115200);

  // 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);
}

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

  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(", Model Number: ");
    DEBUG_SERIAL.println(dxl.getModelNumber(DXL_ID));
  }else{
    DEBUG_SERIAL.print("ping failed!, err code: ");
    DEBUG_SERIAL.println(dxl.getLastLibErrCode());
  }
  delay(500);

  FindServos();
}

DYNAMIXEL::InfoFromPing_t ping_info[32];
void FindServos(void) {
  Serial.println("  Try Protocol 2 - broadcast ping: ");
  Serial.flush(); // flush it as ping may take awhile... 

  if (uint8_t count_pinged = dxl.ping(DXL_BROADCAST_ID, ping_info, 
    sizeof(ping_info)/sizeof(ping_info[0]))) {
    Serial.print("Detected Dynamixel : \n");
    for (int i = 0; i < count_pinged; i++)
    {
      Serial.print("    ");
      Serial.print(ping_info[i].id, DEC);
      Serial.print(", Model:");
      Serial.print(ping_info[i].model_number);
      Serial.print(", Ver:");
      Serial.println(ping_info[i].firmware_version, DEC);
      //g_servo_protocol[i] = 2;
    }
  }else{
    Serial.print("Broadcast returned no items : ");
    Serial.println(dxl.getLastLibErrCode());
  }
}```