I understand that this type of usage is not typical for the pca9685. I am trying to use one of the pwm pins of the pca9685 to regulate the speed of a motor.

As for now the motor works regularly if solely connected to a TB-6612 FNG motor driver without any pwm output connected to it. I then connected the PWM pins on it to the pwm output of the pca9685 and run the following script on my raspberry pi:

import Adafruit_PCA9685
from time import sleep
import RPi.GPIO as GPIO
import signal,sys

pwm = Adafruit_PCA9685.PCA9685()

pinout = {
for i in pinout.values():
    print("setting "+str(i))
    GPIO.output(i["b"][0][0], GPIO.HIGH)
    GPIO.output(i["b"][0][1], GPIO.LOW)

    GPIO.output(i["a"][1], GPIO.HIGH)

def signal_handling(signum,frame):

while True:
    pulse = input("enter pulse duration")
    pulse = int(pulse)
    for i in range(15):
        pwm.set_pwm(i, 0, pulse)

In this case, the motor driver pins A0 and A1 are connected to the GPIO pins 14, 15 and the standby pin is connected to pin 26. However, adjusting the pulse variable as the motor is running does not seem to be having any effect on the speed of the motor connected to it. Is there anything i possibly missed that is causing this problem?

  • Welcome and nice to meet you. Ah, let me see. Using PCA9685 16 channel PWM controller to control TB6612FNG DC motor driver is natural. However, your use of the AdaFruit library seem problematic. You might like to give us a web link to the tutorial or GitHub, so that we can look deeper.
    – tlfong01
    Nov 2 '20 at 12:04
  • 1
    hello! I used this tutorial and simply edited it. can you tell me which part you believe may be causing the problem?
    – vuv
    Nov 2 '20 at 12:52
  • Well, the demo has these two lines: (1) import Adafruit_PCA9685, (2) pwm = Adafruit_PCA9685.PCA9685(). But you don't seem to have imported the module and create the object. You seem to be importing and using the RPi.GPIO instead.
    – tlfong01
    Nov 2 '20 at 13:35
  • 1
    The two lines you mentioned are at the top of the code that I posted, and I am using pwm.set_pwm(i, 0, pulse) to set the pins, am I missing something maybe? Sorry for the obvious question
    – vuv
    Nov 2 '20 at 15:20
  • 1
    no they were there originally, i just edited a small mistake i made with the pwm.set_pwm_freq line. anyways, i decided to try to throttle the motor speed by using diodes directly connected to the pinouts of the motor driver/the power supply since I can't seem to get the pwm throttle to work, thank you for your help anyways! :)
    – vuv
    Nov 3 '20 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.