Circuit Python with PCA9685 on pico

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Tannar
 
Posts: 23
Joined: Sat Nov 26, 2022 7:44 pm

Circuit Python with PCA9685 on pico

Post by Tannar »

I am trying to control servos with a PCA9685 and Raspberry pi Pico board using the editor Mu and Circuit Python. I am new to Circuit python and believe someone with more experience could easily help.

The wiring of the board looks correct. I have downloaded Circuit python and Installed the necessary libraries the tutorial instructs (https://learn.adafruit.com/16-channel-p ... cuitpython) however, when I enter the code that the tutorial uses as a demo to control a standard servo, nothing happens. I don't know if I entered the code incorrectly or if the libraries are imported correctly but some help would be appreciated. I have read as much documentation as I could find but there isn't much and most is outdated

Thanks, Tannar
Attachments
Pico#1.jpg
Pico#1.jpg (114.11 KiB) Viewed 143 times
Pico#3.jpg
Pico#3.jpg (992.3 KiB) Viewed 143 times
Pico#2.jpg
Pico#2.jpg (1021.63 KiB) Viewed 143 times

User avatar
Tannar
 
Posts: 23
Joined: Sat Nov 26, 2022 7:44 pm

Re: Circuit Python with PCA9685 on pico

Post by Tannar »

Here is the code
Attachments
Circuit Library.PNG
Circuit Library.PNG (10.54 KiB) Viewed 142 times
CircuitCode.PNG
CircuitCode.PNG (31.75 KiB) Viewed 142 times

User avatar
Tannar
 
Posts: 23
Joined: Sat Nov 26, 2022 7:44 pm

Re: Circuit Python with PCA9685 on pico

Post by Tannar »

When I run the code there is no twitching or movement whatso ever.

User avatar
Hexen_Wulf
 
Posts: 27
Joined: Tue Aug 02, 2022 9:49 am

Re: Circuit Python with PCA9685 on pico

Post by Hexen_Wulf »

What kind of servo are you talking to? If it's a continuous rotation servo you'll need to apply throttle like it mentions in this guide: https://learn.adafruit.com/16-channel-p ... cuitpython

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Circuit Python with PCA9685 on pico

Post by adafruit_support_carter »

Guessing you're getting a code error with the code as is. Click the "Serial" button to open the serial window and see if you can find the error message output there.

The issue will be in setting up the I2C bus, which is somewhat tricky and special on the Pico. There's some discussion here:
https://learn.adafruit.com/getting-star ... es-3082902

With your code as is, the library will try to use board.I2C(). Since that does not exist for the Pico, it should generate a code error. The fix is fairly easy, just need to modify code a bit. But probably good practice to try seeing the error message in Mu.

User avatar
Tannar
 
Posts: 23
Joined: Sat Nov 26, 2022 7:44 pm

Re: Circuit Python with PCA9685 on pico

Post by Tannar »

Here is the error code. Also the motors are SG90s
Attachments
Mu Error Code.PNG
Mu Error Code.PNG (11.65 KiB) Viewed 138 times

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Circuit Python with PCA9685 on pico

Post by adafruit_support_carter »

Yep. That's the expected error message. That was good practice - now you know where/how to check the output for errors, etc.

The fix is described in a general way on the Learn page linked above. In general, you need to manually setup the I2C bus on the pins being used and pass in that bus to the servokit.

Here's a full example you can try:

Code: Select all

import time
import board
import busio
from adafruit_servokit import ServoKit

i2c = busio.I2C(scl=board.GP1, sda=board.GP0)

kit = ServoKit(i2c=i2c, channels=16)

kit.servo[0].angle = 0
time.sleep(1)
kit.servo[0].angle = 90
time.sleep(1)
kit.servo[0].angle = 180
time.sleep(1)

User avatar
Tannar
 
Posts: 23
Joined: Sat Nov 26, 2022 7:44 pm

Re: Circuit Python with PCA9685 on pico

Post by Tannar »

I ran that code and it still doesn't seem to want to work, Though there were no error messages in the serial. Do you think it might be because the power supply I'm using is only three double A batteries?

User avatar
Hexen_Wulf
 
Posts: 27
Joined: Tue Aug 02, 2022 9:49 am

Re: Circuit Python with PCA9685 on pico

Post by Hexen_Wulf »

What kind of batteries? If they're rechargeable, I think those only top out around 3.7 volts. If they're alkaline I think it's 4.7 volts.

User avatar
Tannar
 
Posts: 23
Joined: Sat Nov 26, 2022 7:44 pm

Re: Circuit Python with PCA9685 on pico

Post by Tannar »

Its an enagizer max batter. but each one is 1.5V so 3X is only 4.5. idk if that is enough

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: Circuit Python with PCA9685 on pico

Post by adafruit_support_carter »

Try removing the battery power connections. Then, *carefully* connect the Pico's VBUS pin to the V+ pin (next to the VCC pin) on the PCA9685 breakout. You will then be powering the servo via your PC's USB port. For a single small servo, that should be OK for a simple functional test.

Could also try running the PCA9685 more directly via its library:
https://github.com/adafruit/Adafruit_Ci ... on_PCA9685

The ServoKit library is just a convenience library built on top of that.

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

Return to “Adafruit CircuitPython”