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

Commit

Permalink
Swap to use Adafruit_GPIO library, port to support both Python 2 and 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdicola committed Feb 17, 2017
1 parent 6ca12b3 commit d772067
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 269 deletions.
158 changes: 0 additions & 158 deletions Adafruit_MotorHAT/Adafruit_I2C.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/python

from Adafruit_PWM_Servo_Driver import PWM
import time

from Adafruit_MotorHAT.Adafruit_PWM_Servo_Driver import PWM


class Adafruit_StepperMotor:
MICROSTEPS = 8
MICROSTEP_CURVE = [0, 50, 98, 142, 180, 212, 236, 250, 255]
Expand Down Expand Up @@ -47,25 +47,25 @@ def oneStep(self, dir, style):

# first determine what sort of stepping procedure we're up to
if (style == Adafruit_MotorHAT.SINGLE):
if ((self.currentstep/(self.MICROSTEPS/2)) % 2):
if ((self.currentstep//(self.MICROSTEPS//2)) % 2):
# we're at an odd step, weird
if (dir == Adafruit_MotorHAT.FORWARD):
self.currentstep += self.MICROSTEPS/2
self.currentstep += self.MICROSTEPS//2
else:
self.currentstep -= self.MICROSTEPS/2
self.currentstep -= self.MICROSTEPS//2
else:
# go to next even step
if (dir == Adafruit_MotorHAT.FORWARD):
self.currentstep += self.MICROSTEPS
else:
self.currentstep -= self.MICROSTEPS
if (style == Adafruit_MotorHAT.DOUBLE):
if not (self.currentstep/(self.MICROSTEPS/2) % 2):
if not (self.currentstep//(self.MICROSTEPS//2) % 2):
# we're at an even step, weird
if (dir == Adafruit_MotorHAT.FORWARD):
self.currentstep += self.MICROSTEPS/2
self.currentstep += self.MICROSTEPS//2
else:
self.currentstep -= self.MICROSTEPS/2
self.currentstep -= self.MICROSTEPS//2
else:
# go to next odd step
if (dir == Adafruit_MotorHAT.FORWARD):
Expand All @@ -74,9 +74,9 @@ def oneStep(self, dir, style):
self.currentstep -= self.MICROSTEPS
if (style == Adafruit_MotorHAT.INTERLEAVE):
if (dir == Adafruit_MotorHAT.FORWARD):
self.currentstep += self.MICROSTEPS/2
self.currentstep += self.MICROSTEPS//2
else:
self.currentstep -= self.MICROSTEPS/2
self.currentstep -= self.MICROSTEPS//2

if (style == Adafruit_MotorHAT.MICROSTEP):
if (dir == Adafruit_MotorHAT.FORWARD):
Expand Down Expand Up @@ -132,7 +132,7 @@ def oneStep(self, dir, style):
[0, 0, 1, 1],
[0, 0, 0, 1],
[1, 0, 0, 1] ]
coils = step2coils[self.currentstep/(self.MICROSTEPS/2)]
coils = step2coils[self.currentstep//(self.MICROSTEPS//2)]

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


class Adafruit_MotorHAT:
FORWARD = 1
BACKWARD = 2
Expand All @@ -223,12 +224,11 @@ class Adafruit_MotorHAT:
INTERLEAVE = 3
MICROSTEP = 4

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

def setPin(self, pin, value):
Expand Down
Loading

0 comments on commit d772067

Please sign in to comment.