Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

Commit d772067

Browse files
committed
Swap to use Adafruit_GPIO library, port to support both Python 2 and 3.
1 parent 6ca12b3 commit d772067

File tree

7 files changed

+132
-269
lines changed

7 files changed

+132
-269
lines changed

Adafruit_MotorHAT/Adafruit_I2C.py

Lines changed: 0 additions & 158 deletions
This file was deleted.

Adafruit_MotorHAT/Adafruit_MotorHAT.py renamed to Adafruit_MotorHAT/Adafruit_MotorHAT_Motors.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/usr/bin/python
2-
3-
from Adafruit_PWM_Servo_Driver import PWM
41
import time
52

3+
from Adafruit_MotorHAT.Adafruit_PWM_Servo_Driver import PWM
4+
5+
66
class Adafruit_StepperMotor:
77
MICROSTEPS = 8
88
MICROSTEP_CURVE = [0, 50, 98, 142, 180, 212, 236, 250, 255]
@@ -47,25 +47,25 @@ def oneStep(self, dir, style):
4747

4848
# first determine what sort of stepping procedure we're up to
4949
if (style == Adafruit_MotorHAT.SINGLE):
50-
if ((self.currentstep/(self.MICROSTEPS/2)) % 2):
50+
if ((self.currentstep//(self.MICROSTEPS//2)) % 2):
5151
# we're at an odd step, weird
5252
if (dir == Adafruit_MotorHAT.FORWARD):
53-
self.currentstep += self.MICROSTEPS/2
53+
self.currentstep += self.MICROSTEPS//2
5454
else:
55-
self.currentstep -= self.MICROSTEPS/2
55+
self.currentstep -= self.MICROSTEPS//2
5656
else:
5757
# go to next even step
5858
if (dir == Adafruit_MotorHAT.FORWARD):
5959
self.currentstep += self.MICROSTEPS
6060
else:
6161
self.currentstep -= self.MICROSTEPS
6262
if (style == Adafruit_MotorHAT.DOUBLE):
63-
if not (self.currentstep/(self.MICROSTEPS/2) % 2):
63+
if not (self.currentstep//(self.MICROSTEPS//2) % 2):
6464
# we're at an even step, weird
6565
if (dir == Adafruit_MotorHAT.FORWARD):
66-
self.currentstep += self.MICROSTEPS/2
66+
self.currentstep += self.MICROSTEPS//2
6767
else:
68-
self.currentstep -= self.MICROSTEPS/2
68+
self.currentstep -= self.MICROSTEPS//2
6969
else:
7070
# go to next odd step
7171
if (dir == Adafruit_MotorHAT.FORWARD):
@@ -74,9 +74,9 @@ def oneStep(self, dir, style):
7474
self.currentstep -= self.MICROSTEPS
7575
if (style == Adafruit_MotorHAT.INTERLEAVE):
7676
if (dir == Adafruit_MotorHAT.FORWARD):
77-
self.currentstep += self.MICROSTEPS/2
77+
self.currentstep += self.MICROSTEPS//2
7878
else:
79-
self.currentstep -= self.MICROSTEPS/2
79+
self.currentstep -= self.MICROSTEPS//2
8080

8181
if (style == Adafruit_MotorHAT.MICROSTEP):
8282
if (dir == Adafruit_MotorHAT.FORWARD):
@@ -132,7 +132,7 @@ def oneStep(self, dir, style):
132132
[0, 0, 1, 1],
133133
[0, 0, 0, 1],
134134
[1, 0, 0, 1] ]
135-
coils = step2coils[self.currentstep/(self.MICROSTEPS/2)]
135+
coils = step2coils[self.currentstep//(self.MICROSTEPS//2)]
136136

137137
#print "coils state = " + str(coils)
138138
self.MC.setPin(self.AIN2, coils[0])
@@ -212,6 +212,7 @@ def setSpeed(self, speed):
212212
speed = 255
213213
self.MC._pwm.setPWM(self.PWMpin, 0, speed*16)
214214

215+
215216
class Adafruit_MotorHAT:
216217
FORWARD = 1
217218
BACKWARD = 2
@@ -223,12 +224,11 @@ class Adafruit_MotorHAT:
223224
INTERLEAVE = 3
224225
MICROSTEP = 4
225226

226-
def __init__(self, addr = 0x60, freq = 1600):
227-
self._i2caddr = addr # default addr on HAT
228-
self._frequency = freq # default @1600Hz PWM freq
227+
def __init__(self, addr = 0x60, freq = 1600, i2c=None, i2c_bus=None):
228+
self._frequency = freq
229229
self.motors = [ Adafruit_DCMotor(self, m) for m in range(4) ]
230230
self.steppers = [ Adafruit_StepperMotor(self, 1), Adafruit_StepperMotor(self, 2) ]
231-
self._pwm = PWM(addr, debug=False)
231+
self._pwm = PWM(addr, debug=False, i2c=i2c, i2c_bus=i2c_bus)
232232
self._pwm.setPWMFreq(self._frequency)
233233

234234
def setPin(self, pin, value):

0 commit comments

Comments
 (0)