I am trying to get pico explorer running with a genneric pca9685 board.
I have flashed the Pimoroni firmware on the PIco. (Examples are running without Problem)
I wrote a Programm to test the pca9685 Programm, wich is working withe the normal-pico-firmware without problems:
from machine import Pin
import servo
from time import sleep_ms
from pimoroni_i2c import PimoroniI2C
# machine.I2C(id, *, scl, sda, freq=400000)
# SCL -> Pin(21)
# SDA -> Pin(20)
ID = 0
#_scl = Pin(1)
#_sda = Pin(0)
_scl = Pin(21)
_sda = Pin(20)
i2c = PimoroniI2C(sda=(20), scl=(21))
adr_room = i2c.scan()
for adr in adr_room:
print(hex(adr))
servo_board = servo.Servos(i2c=i2c)
for _servo in range(16):
_servo_board.position(index=servo, degrees=0)
sleep_ms(3000)
for _servo in range(16):
_servo_board.position(index=servo, degrees=90)
sleep_ms(3000)
for _servo in range(16):
_servo_board.position(index=servo, degrees=180)
When i am running this programm I am getting the error message:
Traceback (most recent call last):
File “”, line 22, in
AttributeError: ‘module’ object has no attribute ‘Servos’
servo.py looks like this:
from pca9685 import PCA9685
import math
class Servos:
def __init__(self, i2c, address=0x40, freq=50, min_us=600, max_us=2400,
degrees=180):
self.period = 1000000 / freq
self.min_duty = self._us2duty(min_us)
self.max_duty = self._us2duty(max_us)
self.degrees = degrees
self.freq = freq
self.pca9685 = PCA9685(i2c, address)
self.pca9685.freq(freq)
def _us2duty(self, value):
return int(4095 * value / self.period)
def position(self, index, degrees=None, radians=None, us=None, duty=None):
span = self.max_duty - self.min_duty
if degrees is not None:
print('Winkel einstellen')
duty = self.min_duty + span * degrees / self.degrees
elif radians is not None:
duty = self.min_duty + span * radians / math.radians(self.degrees)
elif us is not None:
duty = self._us2duty(us)
elif duty is not None:
pass
else:
return self.pca9685.duty(index)
duty = min(self.max_duty, max(self.min_duty, int(duty)))
self.pca9685.duty(index, duty)
def release(self, index):
self.pca9685.duty(index, 0)
What is causing the problem?