pi4j-v1
pi4j-v1 copied to clipboard
PCA9685ServoExample not working
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...
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.