Skip to content

Revert "Merge pull request #23 from plamponi/pwm_freq" #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions adafruit_motor/stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,14 @@ class StepperMotor:
:param ~pulseio.PWMOut bin2: `pulseio.PWMOut`-compatible output connected to the driver for
the fourth coil (unipolar) or second input to second coil (bipolar).
:param int microsteps: Number of microsteps between full steps. Must be at least 2 and even.

.. note:: The ``StepperMotor`` class requires PWM frequencies > 1500. Specify
``frequency=1500`` or higher when instantiating the above ``PWMOut`` objects.
"""
def __init__(self, ain1, ain2, bin1, bin2, *, microsteps=16):
self._coil = (ain2, bin1, ain1, bin2)

# reject unsafe (low) pwm freq
# set a safe pwm freq for each output
for i in range(4):
if self._coil[i].frequency < 1500:
raise ValueError("PWMOut: 'frequency' must be at least 1500")
self._coil[i].frequency = 2000

self._current_microstep = 0
if microsteps < 2:
Expand Down
39 changes: 27 additions & 12 deletions examples/stepper_motor.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
# Run a Stepper Motor. Tested on ItsyBitsy M4 Express + DRV8833.
# https://www.adafruit.com/product/3800
# https://www.adafruit.com/product/3297
# This example uses an Adafruit Stepper and DC Motor FeatherWing to run a Stepper Motor.
# https://www.adafruit.com/product/2927

import time

import board
import pulseio
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

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)
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

stepper_motor = stepper.StepperMotor(AIn1, AIn2, BIn1, BIn2)
# 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.

for i in range(1000):
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(1000):
for i in range(100):
stepper_motor.onestep(direction=stepper.BACKWARD)
time.sleep(0.01)

pca.deinit()
39 changes: 0 additions & 39 deletions examples/stepper_motor_pca9685.py

This file was deleted.