Created
October 4, 2021 07:14
-
-
Save idriszmy/80b0f0449516b3b228586caa7ec22bb1 to your computer and use it in GitHub Desktop.
Control Stepper Motor Using Raspberry Pi 400, Maker HAT Base and MDD3A
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
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | |
# SPDX-License-Identifier: MIT | |
# Use this example for digital pin control of an H-bridge driver | |
# like a DRV8833, TB6612 or L298N. | |
import time | |
import board | |
import digitalio | |
from adafruit_motor import stepper | |
DELAY = 0.01 | |
STEPS = 200 | |
# You can use any available GPIO pin on both a microcontroller and a Raspberry Pi. | |
# The following pins are simply a suggestion. If you use different pins, update | |
# the following code to use your chosen pins. | |
# To use with a Raspberry Pi: | |
coils = ( | |
digitalio.DigitalInOut(board.D18), # A1 | |
digitalio.DigitalInOut(board.D17), # A2 | |
digitalio.DigitalInOut(board.D27), # B1 | |
digitalio.DigitalInOut(board.D22), # B2 | |
) | |
for coil in coils: | |
coil.direction = digitalio.Direction.OUTPUT | |
motor = stepper.StepperMotor(coils[0], coils[1], coils[2], coils[3], microsteps=None) | |
for step in range(STEPS): | |
motor.onestep() | |
time.sleep(DELAY) | |
for step in range(STEPS): | |
motor.onestep(direction=stepper.BACKWARD) | |
time.sleep(DELAY) | |
for step in range(STEPS): | |
motor.onestep(style=stepper.DOUBLE) | |
time.sleep(DELAY) | |
for step in range(STEPS): | |
motor.onestep(direction=stepper.BACKWARD, style=stepper.DOUBLE) | |
time.sleep(DELAY) | |
for step in range(STEPS): | |
motor.onestep(style=stepper.INTERLEAVE) | |
time.sleep(DELAY) | |
for step in range(STEPS): | |
motor.onestep(direction=stepper.BACKWARD, style=stepper.INTERLEAVE) | |
time.sleep(DELAY) | |
motor.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment