adafruit / Adafruit_CircuitPython_ServoKit

CircuitPython helper library for the PWM/Servo FeatherWing, Shield and Pi HAT kits.
MIT License
69 stars 29 forks source link

"ValueError: SCL in use" occur when using Adafruit PCA9685 16-Channel Servo Driver #47

Closed clarayao closed 1 year ago

clarayao commented 1 year ago

Hi! I'm currently trying to drive some servos by using Adafruit PCA9685 16-Channel Servo Driver and Featherwing M4 Express. And I am using the example code in the Adafruit Learning System. However, although I ran the exact same code (with some changes to the I2C address because the PCA9685 board I'm using had been modified), I still get the error Traceback (most recent call last): File "code.py", line 21, in <module> File "adafruit_servokit.py", line 88, in _ _init_ _ ValueError: SCL in use

And this is the code: import board import busio import time import adafruit_pca9685 i2c = busio.I2C(board.SCL, board.SDA) from adafruit_servokit import ServoKit kit = ServoKit(channels=16) kit.servo[0].angle = 180 kit.continuous_servo[1].throttle = 1 time.sleep(1) kit.continuous_servo[1].throttle = -1 time.sleep(1) kit.servo[0].angle = 0 kit.continuous_servo[1].throttle = 0

I wonder where I did wrong. Thank you!

image

caternuson commented 1 year ago

This library takes care of the PCA setup internally. So you don't need explicit lines of code for that, ex:

 i2c = busio.I2C(board.SCL, board.SDA)

See the examples in this library repo for general usage syntax, esp. in how the imports and setup are done: https://github.com/adafruit/Adafruit_CircuitPython_ServoKit/tree/main/examples