-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from plamponi/pwm_freq
PWMOut variable frequency not required, uses only one counter
- Loading branch information
Showing
3 changed files
with
56 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,24 @@ | ||
# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a Stepper Motor. | ||
# https://www.adafruit.com/product/2927 | ||
# Run a Stepper Motor. Tested on ItsyBitsy M4 Express + DRV8833. | ||
# https://www.adafruit.com/product/3800 | ||
# https://www.adafruit.com/product/3297 | ||
|
||
import time | ||
|
||
from board import SCL, SDA | ||
import busio | ||
|
||
# Import the PCA9685 module. Available in the bundle and here: | ||
# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 | ||
from adafruit_pca9685 import PCA9685 | ||
|
||
import board | ||
import pulseio | ||
from adafruit_motor import stepper | ||
|
||
i2c = busio.I2C(SCL, SDA) | ||
|
||
# Create a simple PCA9685 class instance for the Motor FeatherWing's default address. | ||
pca = PCA9685(i2c, address=0x60) | ||
pca.frequency = 1600 | ||
AIn1 = pulseio.PWMOut(board.D9, frequency=1600) | ||
AIn2 = pulseio.PWMOut(board.D10, frequency=1600) | ||
BIn1 = pulseio.PWMOut(board.D11, frequency=1600) | ||
BIn2 = pulseio.PWMOut(board.D12, frequency=1600) | ||
|
||
# Motor 1 is channels 9 and 10 with 8 held high. | ||
# Motor 2 is channels 11 and 12 with 13 held high. | ||
# Motor 3 is channels 3 and 4 with 2 held high. | ||
# Motor 4 is channels 5 and 6 with 7 held high. | ||
stepper_motor = stepper.StepperMotor(AIn1, AIn2, BIn1, BIn2) | ||
|
||
pca.channels[7].duty_cycle = 0xffff | ||
pca.channels[2].duty_cycle = 0xffff | ||
stepper_motor = stepper.StepperMotor(pca.channels[4], pca.channels[3], # Motor 3 | ||
pca.channels[5], pca.channels[6]) # Motor 4 | ||
|
||
for i in range(100): | ||
for i in range(1000): | ||
stepper_motor.onestep() | ||
time.sleep(0.01) | ||
|
||
for i in range(100): | ||
for i in range(1000): | ||
stepper_motor.onestep(direction=stepper.BACKWARD) | ||
time.sleep(0.01) | ||
|
||
pca.deinit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a Stepper Motor. | ||
# https://www.adafruit.com/product/2927 | ||
|
||
import time | ||
|
||
from board import SCL, SDA | ||
import busio | ||
|
||
# Import the PCA9685 module. Available in the bundle and here: | ||
# https://github.com/adafruit/Adafruit_CircuitPython_PCA9685 | ||
from adafruit_pca9685 import PCA9685 | ||
|
||
from adafruit_motor import stepper | ||
|
||
i2c = busio.I2C(SCL, SDA) | ||
|
||
# Create a simple PCA9685 class instance for the Motor FeatherWing's default address. | ||
pca = PCA9685(i2c, address=0x60) | ||
pca.frequency = 1600 | ||
|
||
# Motor 1 is channels 9 and 10 with 8 held high. | ||
# Motor 2 is channels 11 and 12 with 13 held high. | ||
# Motor 3 is channels 3 and 4 with 2 held high. | ||
# Motor 4 is channels 5 and 6 with 7 held high. | ||
|
||
pca.channels[7].duty_cycle = 0xffff | ||
pca.channels[2].duty_cycle = 0xffff | ||
stepper_motor = stepper.StepperMotor(pca.channels[4], pca.channels[3], # Motor 3 | ||
pca.channels[5], pca.channels[6]) # Motor 4 | ||
|
||
for i in range(100): | ||
stepper_motor.onestep() | ||
time.sleep(0.01) | ||
|
||
for i in range(100): | ||
stepper_motor.onestep(direction=stepper.BACKWARD) | ||
time.sleep(0.01) | ||
|
||
pca.deinit() |