|
1 |
| -# Run a Stepper Motor. Tested on ItsyBitsy M4 Express + DRV8833. |
2 |
| -# https://www.adafruit.com/product/3800 |
3 |
| -# https://www.adafruit.com/product/3297 |
| 1 | +# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a Stepper Motor. |
| 2 | +# https://www.adafruit.com/product/2927 |
4 | 3 |
|
5 | 4 | import time
|
6 | 5 |
|
7 |
| -import board |
8 |
| -import pulseio |
| 6 | +from board import SCL, SDA |
| 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 | + |
9 | 13 | from adafruit_motor import stepper
|
10 | 14 |
|
11 |
| -AIn1 = pulseio.PWMOut(board.D9, frequency=1600) |
12 |
| -AIn2 = pulseio.PWMOut(board.D10, frequency=1600) |
13 |
| -BIn1 = pulseio.PWMOut(board.D11, frequency=1600) |
14 |
| -BIn2 = pulseio.PWMOut(board.D12, frequency=1600) |
| 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 |
15 | 20 |
|
16 |
| -stepper_motor = stepper.StepperMotor(AIn1, AIn2, BIn1, BIn2) |
| 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. |
17 | 25 |
|
18 |
| -for i in range(1000): |
| 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], # Motor 3 |
| 29 | + pca.channels[5], pca.channels[6]) # Motor 4 |
| 30 | + |
| 31 | +for i in range(100): |
19 | 32 | stepper_motor.onestep()
|
20 | 33 | time.sleep(0.01)
|
21 | 34 |
|
22 |
| -for i in range(1000): |
| 35 | +for i in range(100): |
23 | 36 | stepper_motor.onestep(direction=stepper.BACKWARD)
|
24 | 37 | time.sleep(0.01)
|
| 38 | + |
| 39 | +pca.deinit() |
0 commit comments