pi4j-v1 icon indicating copy to clipboard operation
pi4j-v1 copied to clipboard

PCA9685ServoExample not working

Open luke-ff opened this issue 7 years ago • 1 comments

I've tried to test the PCA9685 servo examples. They don't work, and I managed to figure out, where the problem might be located:

Taking a look at com.pi4j.component.servo.impl.GenericServo.setPositon():

public void setPosition(float position) { this.position = validatePosition(position); pwmDuration = calculatePwmDuration(position); servoDriver.setServoPulseWidth(pwmDuration); }

  • calculatePwmDuration does not return a duration, but a value between 0 and 4096
  • setServoPulseWidth calls setPwm(Pin, int duration) (where duration is microseconds)

this results in wrong signals...

luke-ff avatar Feb 11 '18 19:02 luke-ff

A work around is to use setServoPulseWidth directly, all you need to do is interpolate between minimum and maxium pulse-width in microseconds, e.g. 500 to 2500 which might correspond to 0 to 180 degrees.

Sciss avatar Jun 12 '21 18:06 Sciss