Skip to content

AttributeError: module 'board' has no attribute 'I2C' #7

Closed
@sumghai

Description

@sumghai

Summary of Issue

Attempting to initialize the class object from ServoKit results in the following error:

Traceback (most recent call last):
  File "servo_test.py", line 3, in <module>
    kit = ServoKit(channels=16)
  File "/usr/local/lib/python3.5/dist-packages/adafruit_servokit.py", line 85, in __init__
    i2c = board.I2C()
AttributeError: module 'board' has no attribute 'I2C'

Hardware

  • Raspberry Pi 3 Model B
  • Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface - PCA9685
  • (2x) GWS S03T STD Servos

Software and Environment

servo_test.py

import time
from adafruit_servokit import ServoKit
kit = ServoKit(channels=16)

# Tuned for GWS S03T STD Servos
kit.servo[0].set_pulse_width_range(775, 2450)
kit.servo[1].set_pulse_width_range(775, 2450)

# Return servos to starting positions
kit.servo[0].angle = 0
kit.servo[1].angle = 180
time.sleep(1)

while True:
    for tgtAngle in range(0, 180, 1):
        kit.servo[0].angle = tgtAngle
        kit.servo[1].angle = 180 - tgtAngle
        time.sleep(0.1)
    for tgtAngle in range(180, 0, -1):
        kit.servo[0].angle = tgtAngle
        kit.servo[1].angle = 180 - tgtAngle
        time.sleep(0.1)

Notes

  • I previously had CircuitPython ServoKit working with the Python code sample and two servos one week ago
  • This morning, I had to completely reformat and re-setup my Raspberry Pi due to an unrelated issue
  • After reinstalling CircuitPython ServoKit and all dependencies from scratch, I found that my existing code no longer works and instead returned the titular error message, so I presume there was a change in adafruit_servokit.py between my two installations
  • Examining adafruit_servokit.py, I noticed that line 85 was previously (828a46c) defined as i2c = busio.I2C(board.SCL, board.SDA) instead of the current i2c = board.I2C(); perhaps this line may be of interest
  • The blinkatest.py example currently still works because it uses the older i2c = busio.I2C(board.SCL, board.SDA)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions