need coding help: chaining PCA9685 servos with raspberry pi4b

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
UncleDenz
 
Posts: 4
Joined: Fri Mar 17, 2023 12:54 am

need coding help: chaining PCA9685 servos with raspberry pi4b

Post by UncleDenz »

I am not new to programming... I AM new to python.

I have been spending hours trying to piece together code from tutorials... but I need help.

I cannot find how to send commands to digital servos on multiple boards.

I have a robotics project with 56 motors... I am using Raspberry Pi 4b, and 4x PCA9685's.

to identify each board:

-----------------------------------------------
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver board1 = Adafruit_PWMServoDriver(0x40)
Adafruit_PWMServoDriver board2 = Adafruit_PWMServoDriver(0x41)
Adafruit_PWMServoDriver board3 = Adafruit_PWMServoDriver(0x42)
Adafruit_PWMServoDriver board4 = Adafruit_PWMServoDriver(0x43)

board1.begin();
board2.begin();
board1.setPWMFreq(50);
board2.setPWMFreq(50);
etc
-----------------------------------------------

and, driving servos on one board seems easy:

-----------------------------------------------
from adafruit_servokit import ServoKit
kit = ServoKit(channels=16)

while True:
degree=input("enter angle:-")

kit.servo[0].angle = int(degree)
kit.servo[1].angle = int(degree)
-----------------------------------------------

but, I cannot find how to tell kit.servo[x] to address the motors on each separate board.

Can someone please help me fill in the blanks on what I'm missing?

Thank you!!

User avatar
dastels
 
Posts: 15820
Joined: Tue Oct 20, 2015 3:22 pm

Re: need coding help: chaining PCA9685 servos with raspberry pi4b

Post by dastels »

Your post contains a mix of C++ Python. And you don't need that first chunk of code, and it won't work in Python anyway since it's not completely python.

To use multiple boards in Python you need to create a ServoKit for each board. E.g.

Code: Select all

kit1 = ServoKit(channels=16, address=0x40)
kit2 = ServoKit(channels=16, address=0x41)
etc.
Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”