From 723b805fd143f644d664228fd0f673986df14263 Mon Sep 17 00:00:00 2001 From: adario7 <24436551+adario7@users.noreply.github.com> Date: Fri, 9 Aug 2019 00:10:10 +0200 Subject: [PATCH 1/2] Support Different Microsteps interval Allow the user to specify in the MotorKit constructur how many microsteps shall the the stepper motors do. --- adafruit_motorkit.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/adafruit_motorkit.py b/adafruit_motorkit.py index 5eef37e..b8c7a88 100644 --- a/adafruit_motorkit.py +++ b/adafruit_motorkit.py @@ -63,7 +63,7 @@ class MotorKit: """Class representing an Adafruit DC & Stepper Motor FeatherWing, Shield or Pi Hat kit. Automatically uses the I2C bus on a Feather, Metro or Raspberry Pi.""" - def __init__(self, address=0x60, i2c=None): + def __init__(self, address=0x60, i2c=None, stepper_microsteps=16): self._motor1 = None self._motor2 = None self._motor3 = None @@ -74,6 +74,7 @@ def __init__(self, address=0x60, i2c=None): i2c = board.I2C() self._pca = PCA9685(i2c, address=address) self._pca.frequency = 1600 + self.stepper_microsteps = stepper_microsteps # We can save memory usage (~300 bytes) by deduplicating the construction of the objects for # each motor. This saves both code size and the number of raw strings (the error message) @@ -227,7 +228,8 @@ def stepper1(self): self._pca.channels[8].duty_cycle = 0xffff self._pca.channels[13].duty_cycle = 0xffff self._stepper1 = stepper.StepperMotor(self._pca.channels[10], self._pca.channels[9], - self._pca.channels[11], self._pca.channels[12]) + self._pca.channels[11], self._pca.channels[12], + microsteps=self.stepper_microsteps) return self._stepper1 @property @@ -261,5 +263,6 @@ def stepper2(self): self._pca.channels[7].duty_cycle = 0xffff self._pca.channels[2].duty_cycle = 0xffff self._stepper2 = stepper.StepperMotor(self._pca.channels[4], self._pca.channels[3], - self._pca.channels[5], self._pca.channels[6]) + self._pca.channels[5], self._pca.channels[6], + microsteps=self.stepper_microsteps) return self._stepper2 From fd7ba9783038af45efd860d08b8c44fcd1c83c25 Mon Sep 17 00:00:00 2001 From: adario7 <24436551+adario7@users.noreply.github.com> Date: Fri, 9 Aug 2019 12:46:41 +0200 Subject: [PATCH 2/2] Mark steppers_microsteps field as private change field name steppers_microsteps to _steppers_microsteps as it is a private field. --- adafruit_motorkit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_motorkit.py b/adafruit_motorkit.py index b8c7a88..114f542 100644 --- a/adafruit_motorkit.py +++ b/adafruit_motorkit.py @@ -63,7 +63,7 @@ class MotorKit: """Class representing an Adafruit DC & Stepper Motor FeatherWing, Shield or Pi Hat kit. Automatically uses the I2C bus on a Feather, Metro or Raspberry Pi.""" - def __init__(self, address=0x60, i2c=None, stepper_microsteps=16): + def __init__(self, address=0x60, i2c=None, steppers_microsteps=16): self._motor1 = None self._motor2 = None self._motor3 = None @@ -74,7 +74,7 @@ def __init__(self, address=0x60, i2c=None, stepper_microsteps=16): i2c = board.I2C() self._pca = PCA9685(i2c, address=address) self._pca.frequency = 1600 - self.stepper_microsteps = stepper_microsteps + self._steppers_microsteps = steppers_microsteps # We can save memory usage (~300 bytes) by deduplicating the construction of the objects for # each motor. This saves both code size and the number of raw strings (the error message) @@ -229,7 +229,7 @@ def stepper1(self): self._pca.channels[13].duty_cycle = 0xffff self._stepper1 = stepper.StepperMotor(self._pca.channels[10], self._pca.channels[9], self._pca.channels[11], self._pca.channels[12], - microsteps=self.stepper_microsteps) + microsteps=self._steppers_microsteps) return self._stepper1 @property @@ -264,5 +264,5 @@ def stepper2(self): self._pca.channels[2].duty_cycle = 0xffff self._stepper2 = stepper.StepperMotor(self._pca.channels[4], self._pca.channels[3], self._pca.channels[5], self._pca.channels[6], - microsteps=self.stepper_microsteps) + microsteps=self._steppers_microsteps) return self._stepper2