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
Circuit Python with PCA9685 on pico
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Tannar
- Posts: 23
- Joined: Sat Nov 26, 2022 7:44 pm
Circuit Python with PCA9685 on pico
- Attachments
-
- Pico#1.jpg (114.11 KiB) Viewed 143 times
-
- Pico#3.jpg (992.3 KiB) Viewed 143 times
-
- Pico#2.jpg (1021.63 KiB) Viewed 143 times
- Tannar
- Posts: 23
- Joined: Sat Nov 26, 2022 7:44 pm
Re: Circuit Python with PCA9685 on pico
Here is the code
- Attachments
-
- Circuit Library.PNG (10.54 KiB) Viewed 142 times
-
- CircuitCode.PNG (31.75 KiB) Viewed 142 times
- Tannar
- Posts: 23
- Joined: Sat Nov 26, 2022 7:44 pm
Re: Circuit Python with PCA9685 on pico
When I run the code there is no twitching or movement whatso ever.
- Hexen_Wulf
- Posts: 27
- Joined: Tue Aug 02, 2022 9:49 am
Re: Circuit Python with PCA9685 on pico
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
- adafruit_support_carter
- Posts: 29056
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Circuit Python with PCA9685 on pico
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.
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.
- Tannar
- Posts: 23
- Joined: Sat Nov 26, 2022 7:44 pm
Re: Circuit Python with PCA9685 on pico
Here is the error code. Also the motors are SG90s
- Attachments
-
- Mu Error Code.PNG (11.65 KiB) Viewed 138 times
- adafruit_support_carter
- Posts: 29056
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Circuit Python with PCA9685 on pico
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:
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)
- Tannar
- Posts: 23
- Joined: Sat Nov 26, 2022 7:44 pm
Re: Circuit Python with PCA9685 on pico
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?
- Hexen_Wulf
- Posts: 27
- Joined: Tue Aug 02, 2022 9:49 am
Re: Circuit Python with PCA9685 on pico
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.
- Tannar
- Posts: 23
- Joined: Sat Nov 26, 2022 7:44 pm
Re: Circuit Python with PCA9685 on pico
Its an enagizer max batter. but each one is 1.5V so 3X is only 4.5. idk if that is enough
- adafruit_support_carter
- Posts: 29056
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Circuit Python with PCA9685 on pico
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.
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.
Please be positive and constructive with your questions and comments.