0

Turn Off a Specific Pin on PCA9685
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Turn Off a Specific Pin on PCA9685

by tz3p9v on Tue Apr 27, 2021 3:27 pm

I use micro-servos to operate turnouts on a model railway -- the servos are moved to a position and may stay there for an extended period. Typically the servo can maintain the position while the power is off, so I wanted to turn off the specific servo's PWM pin power. I currently force the entire board to Sleep which does the same but for all pins. I need to Wake the board prior to issuing any new changes to the servos which then returns power to all. Seems rather messy so I wanted a way to turn off a specific servo's PIN.

Using the PCA9695's datasheet, I determined that you can issue a FULL OFF to a specific pin, so I created the function setPWMOff by added the following to the local copy of the Adafruit_PWMServoDriver library (.cpp and added prototype to .h). I know it's "bad form" to tweak the libraries -- but it was faster than creating an inherited class as my C++ skills are limited.

Code: Select all | TOGGLE FULL SIZE
/*!
   *  @brief  Sets the PWM output Off for one of the PCA9685 output pins
   *  @param  num One of the PWM output pins, from 0 to 15
   *  @param  off Full off value = 16
   */
  void Adafruit_PWMServoDriver::setPWMOff(uint8_t num, uint8_t off = 16) {
  #ifdef ENABLE_DEBUG_OUTPUT
      Serial.print("Setting PWM Off ");
      Serial.print(num);
      Serial.print(": ");   
      Serial.println(off);
  #endif

      _i2c->beginTransmission(_i2caddr);
      _i2c->write(PCA9685_LED0_OFF_H + 4 * num);   
      _i2c->write(off);
      _i2c->endTransmission();
  }


Turning off the PWM power also stops the buzzzing that can occur while a servo attempts to maintain a specific position. The buzzing will lead to a premature failure of the servo.

Possibly this type of functionality could be added to the PWMServoDriver Library in the future ??? please

Hope this helps
/Paul

tz3p9v
 
Posts: 3
Joined: Sun Oct 29, 2017 3:08 pm

Re: Turn Off a Specific Pin on PCA9685

by adafruit_support_mike on Tue Apr 27, 2021 11:47 pm

You can also set any PCA9685 pin to a 0% duty cycle by calling .setPWM() with an ON value that's higher than the OFF value.

adafruit_support_mike
 
Posts: 63053
Joined: Thu Feb 11, 2010 2:51 pm

Re: Turn Off a Specific Pin on PCA9685

by tz3p9v on Wed Apr 28, 2021 10:58 am

That's a detail I did not know -- possible something to add to Library documentation. I looked a several libraries looking for a way to "turn off" a pin and I could not find it - at least not express in layman's terms.

Thanks for the addition info!
/Paul

tz3p9v
 
Posts: 3
Joined: Sun Oct 29, 2017 3:08 pm

Please be positive and constructive with your questions and comments.