4

I use my Arduino with Adafruit PCA9685 servo controller. To set PWM signals I use the provided library: https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library

It allows easily set PMM signal and works good. But how can I "unset" PWM signal for a certain pin?

If a PWM siganl is active, the servo stucks on the current position and can't be moved by hand, but only by setting other pulse length. So I need to move servo and then "free" it.

5 Answers5

3

You can try to send no "ON" time to your output pin on the PCA9685. So, you start the "ON" at 0 and stop the "OFF" at 0.

void freeServo(uint8_t servoIdx)
{
  pwm.setPWM(servoIdx, 0, 0 );
}
0

You could try changing the corresponding pin from output to input. To be sure not to disturb other comfigurations you could do direct port manipulation.

void servo_off() {
  DDRD &= ~(1<<PD5);
}

void servo_on() {
  DDRD |= (1<<PD5);
}

This assumes you use pin PD5 for the pwm signal. Adjust the "D" in DDRD and PD5 so it matches the port in use as well as the pin number.

Of course, you need some additional user input like a button to trigger calls to those functions.

Sim Son
  • 1,878
  • 13
  • 21
0

Are your servo's control pins active high or active low?

From the library code at https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library/blob/d265f74fc0e66632e6dafc787c95b008f3245550/Adafruit_PWMServoDriver.cpp#L242 it looks like there are special on&off values of setPWM(pin,on,off) that turn the servo fully on or fully off, and how they work they depends on whether the servo pin is active high or active low.

unsigned byte idle = CertainPin;

servoController01.setPWM(idle, 0, 4096); // fully off Active high // servoController01.setPWM(idle, 4096, 0); // fully off Active low

or with the better documented setPin():

servoController01.setPin(idle,0,false); // Active high
//servoController01.setPin(idle,0,true); // Active low
Dave X
  • 2,350
  • 15
  • 29
-1

Unluckily, AFAIK, the servo powers the motor even when the PWM signal is not applied. So "removing" the PWM is useless.

You will have to "turn off" the servo by removing the power. To do this, use a transistor (usually servos are more current-hungry than arduino can bear). When you want to "free" the servo, remove the power and it will be "free".

frarugi87
  • 2,731
  • 12
  • 19
-1

I got same problem, searched around but found no answer, so I looked into the source code and found that you simply have to set the angle of the servo to 'None' to stop sending PWM pulses to the servo. For example, if your servo uses channel 14 on the PCA9685 board:

kit.servo[14].angle = None