Skip to content

Commit e73840a

Browse files
committed
Steppers work!
1 parent c4ab3e3 commit e73840a

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

adafruit_motor/__init__.py

Whitespace-only changes.

adafruit_motor/stepper.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def _update_coils(self, *, microstepping=False):
9797

9898
# Energize coils as appropriate:
9999
for i in range(4):
100-
print(i, hex(duty_cycles[i]))
101100
self._coil[i].duty_cycle = duty_cycles[i]
102101

103102
def onestep(self, *, direction=FORWARD, style=SINGLE):
@@ -138,15 +137,11 @@ def onestep(self, *, direction=FORWARD, style=SINGLE):
138137
elif style == SINGLE or style == DOUBLE:
139138
step_size = full_step
140139

141-
print(step_size, MICROSTEP)
142-
143140
if direction == FORWARD:
144141
self._current_microstep += step_size
145142
else:
146143
self._current_microstep -= step_size
147144

148-
print(self._current_microstep)
149-
150145
# Now that we know our target microstep we can determine how to energize the four coils.
151146
self._update_coils(microstepping=style == MICROSTEP)
152147

examples/stepper_motor.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a DC Motor.
2+
# https://www.adafruit.com/product/2927
3+
4+
import time
5+
6+
from board import *
7+
import busio
8+
9+
# Import the PCA9685 module. Available in the bundle and here:
10+
# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685
11+
from adafruit_pca9685 import PCA9685
12+
13+
from adafruit_motor import stepper
14+
15+
i2c = busio.I2C(SCL, SDA)
16+
17+
# Create a simple PCA9685 class instance for the Motor FeatherWing's default address.
18+
pca = PCA9685(i2c, address=0x60)
19+
pca.frequency = 1600
20+
21+
# Motor 1 is channels 9 and 10 with 8 held high.
22+
# Motor 2 is channels 11 and 12 with 13 held high.
23+
# Motor 3 is channels 3 and 4 with 2 held high.
24+
# Motor 4 is channels 5 and 6 with 7 held high.
25+
26+
pca.channels[7].duty_cycle = 0xffff
27+
pca.channels[2].duty_cycle = 0xffff
28+
stepper_motor = stepper.StepperMotor(pca.channels[4], pca.channels[3], pca.channels[5], pca.channels[6], microsteps=4)
29+
30+
for i in range(100):
31+
stepper_motor.onestep()
32+
time.sleep(0.01)
33+
34+
for i in range(100):
35+
stepper_motor.onestep(direction=stepper.BACKWARD)
36+
time.sleep(0.01)
37+
38+
pca.deinit()

0 commit comments

Comments
 (0)