timmaxw / HitecDServo

Arduino library to program and control Hitec D-Series servos. (Not endorsed by Hitec.)
MIT License
5 stars 3 forks source link

Support for Hitec HSR-M9382TH? #2

Open hikari20XX opened 5 months ago

hikari20XX commented 5 months ago

Hello,

I was wondering if this library would recognize a Hitec HSR-M9382TH servo motor if connected (since they both use the DPC-11 programmer figured it might be worth a shot)? So far I've been unable to verify the that the servo is connected in the serial monitor, but will continue troubleshooting in the meantime. I've replicated the breadboard layout in the README (using an Arduino Nano), and I've confirmed that the servo is receiving the correct voltage and is drawing amperage indicative of idling. Any insights or wisdom is greatly appreciated.

Thanks again for your time.

hikari20XX commented 5 months ago

Update: I realized that I had omitted a resistor, and now in the serial monitor when I try to set the pin the response is Error: Corrupt response from servo.

timmaxw commented 5 months ago

I've never tried an HSR-series servo, but I'm not surprised that it doesn't work.

(Hitec's marketing for the D-series advertises shiny new "32-bit chip technology", so I think the D-series might use a different processor+firmware than Hitec's other lines? IDK.)

hikari20XX commented 5 months ago

Thanks for getting back to me so quickly, I really appreciate it. Do you have any advice for developing a library for it, or adding compatibility for it in your library? Like did you use Ghidra when developing your library, or did you have a DPC-11 and captured the communication between the programmer and servo with an oscilloscope/logic analyzer?

timmaxw commented 5 months ago

I used a DPC-11 and a logic analyzer. I put some notes in the repo here, which may or may not be helpful for reverse-engineering the HSR-series:

TTN- commented 2 months ago

FYI have tried the programmer sketch with a D645MW servo, but no joy. Comes back with Error: Corrupt response from servo.

timmaxw commented 2 months ago

That's a bummer. I wonder why the D645MW doesn't work; I would have expected the protocol to be pretty similar.

I don't have a D645MW, so I can't debug this myself. If you're interested in debugging this, the next step would be to modify the HitecDServo::readRawRegister() method to print which part of the message was corrupt.

TTN- commented 2 months ago

Thanks. I'm not a very good programmer it's been a while so I'll be super verbose:

HitecDServo.cpp from Example3_ReadSettings was modded:

#include "HitecDServo.h"

#include "HitecDServoInternal.h"

HitecDServo::HitecDServo() : pin(-1) { }

int HitecDServo::attach(int _pin) {
  if (attached()) {
    detachAndReset();
  }

  pin = _pin;
  pinMode(pin, OUTPUT);
  digitalWrite(pin, LOW);

  pinBitMask = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  pinInputRegister = portInputRegister(port);
  pinOutputRegister = portOutputRegister(port);

  int res;
  uint16_t temp;

  res = readRawRegister(HD_REG_MODEL_NUMBER, &temp);
  Serial.println("read: HD_REG_MODEL_NUMBER as: ");
  Serial.println(temp);
  Serial.println(res);

  res = readRawRegister(HD_REG_RANGE_LEFT_APV, &temp);
  Serial.println("read: HD_REG_RANGE_LEFT_APV as: ");
  Serial.println(temp);
  Serial.println(res);

    res = readRawRegister(HD_REG_RANGE_RIGHT_APV, &temp);
  Serial.println("read: HD_REG_RANGE_RIGHT_APV as: ");
  Serial.println(temp);
  Serial.println(res);

    res = readRawRegister(HD_REG_RANGE_CENTER_APV, &temp);
  Serial.println("read: HD_REG_RANGE_CENTER_APV as: ");
  Serial.println(temp);
  Serial.println(res);

Then power cycle the servo, and then run the arduino, result:

06:07:58.411 -> read: HD_REG_MODEL_NUMBER as: 
06:07:58.411 -> 309
06:07:58.411 -> read: HD_REG_RANGE_LEFT_APV as: 
06:07:58.411 -> 309
06:07:58.458 -> read: HD_REG_RANGE_RIGHT_APV as: 
06:07:58.458 -> 309
06:07:58.458 -> read: HD_REG_RANGE_CENTER_APV as: 
06:07:58.458 -> 309
06:07:58.506 -> Error: Corrupt response from servo.

Something is off. Got 2K pullup from D2 to 5V. Servo powered from external 5V power source, and grounds are shared between Arduino and servo so that should be fine wiring wise. Have verified with multimeter, it does pull up with reference to arduino gnd.

timmaxw commented 2 months ago

What does it print if you run it with this patch? https://github.com/timmaxw/HitecDServo/compare/main...debug

TTN- commented 2 months ago

Tim I'll throw up a logic analyzer dump in https://github.com/timmaxw/HitecDServo/issues/3 later today.