1- #!/usr/bin/python
2-
3- from Adafruit_PWM_Servo_Driver import PWM
41import time
52
3+ from Adafruit_MotorHAT .Adafruit_PWM_Servo_Driver import PWM
4+
5+
66class 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+
215216class 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