Just curious: Was I2C enabled on the Pi’s where the motorHAT is not working?
This is the code from motor.py (lines 40 to 62 included) Lines 40 and 58 as in error code are in bold.
class DCMotor:
**"""DC motor driver. ``positive_pwm`` and ``negative_pwm`` can be swapped if the motor runs in**
** the opposite direction from what was expected for "forwards".**
Motor controller recirculation current decay mode is selectable and defaults to
``motor.FAST_DECAY`` (coasting). ``motor.SLOW_DECAY`` is recommended to improve spin
threshold, speed-to-throttle linearity, and PWM frequency sensitivity.
Decay mode settings only effect the operational performance of controller chips such
as the DRV8833, DRV8871, and TB6612. Either decay mode setting is compatible
with discrete h-bridge controller circuitry such as the L9110H and L293D; operational
performance is not altered.
:param ~pwmio.PWMOut positive_pwm: The motor input that causes the motor to spin forwards
when high and the other is low.
:param ~pwmio.PWMOut negative_pwm: The motor input that causes the motor to spin backwards
when high and the other is low."""
**def __init__(self, positive_pwm: PWMOut, negative_pwm: PWMOut) -> None:**
self._positive = positive_pwm
self._negative = negative_pwm
self._throttle = None
self._decay_mode = FAST_DECAY
The second traceback error is to import the motor.py
def _motor(self, motor_name, channels, stepper_name):
**from adafruit_motor import motor # pylint: disable=import-outside-toplevel**
** motor_name = "_motor" + str(motor_name)**
** stepper_name = "_stepper" + str(stepper_name)**
if not getattr(self, motor_name):
if getattr(self, stepper_name):
raise RuntimeError(
"Cannot use {} at the same time as {}.".format(
motor_name[1:], stepper_name[1:]
The topmost traceback is for Motor 1
@property
def motor1(self):
"""**:py:class:``~adafruit_motor.motor.DCMotor`` controls for motor 1.**
** The following image shows the location of the M1** terminal on the DC/Stepper FeatherWing.
The label on the FeatherWing is found on the bottom of the board.
The terminal is labeled on the top of the Shield and Pi Hat.
.. image :: ../docs/_static/motor_featherwing/m1.jpg
:alt: Motor 1 location
This example moves the motor forwards for one fifth of a second at full speed.
.. code-block:: python
import time
from adafruit_motorkit import motorkit
kit = MotorKit()
kit.motor1.throttle = 1.0
time.sleep(0.2)
kit.motor1.throttle = 0
"""
**return self._motor(1, (8, 9, 10), 1)**
Basically, when the script looks for motor 1, and calls in for the parameters, it could not find the definition for the PWM. Read somewhere the I2C, if not enabled, can cause these issues. Adafruit MotorHat requires I2C to be enabled. If it works on some of the Pi’s and not in others, is it possible that it is not enabled inadverently?
If this does not help, someone with more experience with Python and this specific product’s troubleshooting can help