0

Servo bonnet stacking
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

Servo bonnet stacking

by desi_d123 on Thu Feb 13, 2020 10:21 pm

Hello all...
I’m having a little bit trouble stacking two Adafruit servo bonnets on raspberry pi.

I’ve provided separate power for both bonnets and jumped the “a0” pad on the second one. The bonnets are stacked, but when i look on i2c (using sudo i2cdetect -y 1) the second board isn’t listed.

Also, how do I program the second board in python? Like how do I differentiate the two board in the code.
I gone over the tutorial several times and still don’t really get how to program the second bonnet.

I’ve got the first one to work but haven’t been able to test the second for I don’t know how to code it?
Could someone provide example code for me on how to program both, please.

Sorry if it’s a silly question I’m new to this, any help is appreciated! Good day :)

desi_d123
 
Posts: 7
Joined: Tue Jul 02, 2019 6:30 pm

Re: Servo bonnet stacking

by desi_d123 on Fri Feb 14, 2020 12:31 am

So let me clarify my question...
In the Arduino version of this board, you have to differentiate between the two boards in the code. (Here an example; viewtopic.php?f=31&t=59001)
How do I do this for the Raspberry pi bonnet?
Thanks again

desi_d123
 
Posts: 7
Joined: Tue Jul 02, 2019 6:30 pm

Re: Servo bonnet stacking

by dastels on Fri Feb 14, 2020 12:31 am

Check that your work on the a0 pad is good: good bridging, and no shorts around it.

It should be showing up in the I2C scan. Check that all connections in the stacking are good.

Give https://learn.adafruit.com/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi/ a careful read if you haven't.

To use the second bonnet, you have to create a second object using it's I2C address. E.g.:
Code: Select all | TOGGLE FULL SIZE
hat1 = adafruit_pca9685.PCA9685(i2c, address=0x40)
hat2 = adafruit_pca9685.PCA9685(i2c, address=ox41)


Dave

dastels
 
Posts: 1643
Joined: Tue Oct 20, 2015 3:22 pm

Re: Servo bonnet stacking

by desi_d123 on Fri Feb 14, 2020 12:58 am

@dastels
Ok just to clarify... is this the correct code?
Code: Select all | TOGGLE FULL SIZE
import time
from adafruit_servokit import ServoKit

hat1 = adafruit_pca9685.PCA9685(i2c, address=0x40)
hat2 = adafruit_pca9685.PCA9685(i2c, address=0x41)

kit = ServoKit(channels=16)

def main():
    kit.servo[16].angle = 90
    time.sleep(1)
main()



There aren't any libraries that I need to download/import? Or anything else I need to add? Thanks so much for the quick reply and help I appreciate it :)

desi_d123
 
Posts: 7
Joined: Tue Jul 02, 2019 6:30 pm

Re: Servo bonnet stacking

by dastels on Fri Feb 14, 2020 1:04 am

Read the guide, specifically the page on using it with Python: https://learn.adafruit.com/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi/using-the-python-library.

Dave

dastels
 
Posts: 1643
Joined: Tue Oct 20, 2015 3:22 pm

Re: Servo bonnet stacking

by desi_d123 on Fri Feb 14, 2020 1:44 am

@dastels
Hi-ya
after re-reading and studying the tutorial I've edited my code to the following
Code: Select all | TOGGLE FULL SIZE
import time
import board
import busio
from adafruit_servokit import ServoKit
import adafruit_pca9685
i2c = busio.I2C(board.SCL, board.SDA)
pca = adafruit_pca9685.PCA9685(i2c)

hat1 = adafruit_pca9685.PCA9685(i2c, address=0x40)
hat2 = adafruit_pca9685.PCA9685(i2c, address=0x41)

kit = ServoKit(channels=16)

def main():
    class adafruit_pca9685.PCA(i2c_bus, *, address=0x41, reference_clock_speed=25000000)
    kit.servo[15].angle = 90
    time.sleep(1)
main()



I've run this code but gotten an error on the "class" line specifically is says the "." is invalid syntax.

Any ideas as to what I'm doing wrong, sorry for so many questions just trying to get this figured out
thanks again :)

desi_d123
 
Posts: 7
Joined: Tue Jul 02, 2019 6:30 pm

Re: Servo bonnet stacking

by dastels on Fri Feb 14, 2020 9:51 am

It would benefit you to deepen your knowledge of Python. Copy & paste coding will only get you so far. The reason you are getting an error on the class line is that it isn't well formed Python code.

The code you posted is trying to use both the PCA9685 class directly as well as the ServoKit class (which uses the PCA9685 class internally). The first thing you need to do is decide which you want to use. I recommend the latter. This page in the tutorial has the information: https://learn.adafruit.com/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi/using-the-python-library. The only difference will be using the second hat. The default constructor for the ServoKit class uses defaults to handle the case of a single hat at I2C address 0x40. To handle two hats, you will need to create two ServoKit objects. For example:

Code: Select all | TOGGLE FULL SIZE
import board
import busio
from adafruit_servokit import ServoKit
i2c = busio.I2C(board.SCL, board.SDA)
kit1 = ServoKit(channels=16, i2c=i2c, address=0x40)
kit2 = ServoKit(channels=16, i2c=i2c, address=0x41)
kit1.servo[15].angle = 90
kit2.servo[15].angle = 90


Dave

dastels
 
Posts: 1643
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.