Files
micropython-testing/drv8825.py
2026-05-10 13:03:17 +02:00

40 lines
932 B
Python

from time import sleep
from machine import PWM, Pin
class DRV8825:
LEFT = 0
RIGHT = 1
def __init__(
self,
dir_pin: Pin,
step_pin: Pin,
sleep_pin: Pin,
rst_pin: Pin,
# microstep_pins: tuple[Pin, Pin, Pin],
) -> None:
self.sleep_pin = sleep_pin
self.step_pin = PWM(step_pin, freq=1000, duty_u16=0)
self.dir_pin = dir_pin
self.rst_pin = rst_pin
# self.microstep_pins = microstep_pins
pass
def init(self):
self.sleep_pin.on()
self.rst_pin.on()
def set_direction(self, direction: int) -> None:
if direction == self.LEFT:
self.dir_pin.off()
else:
self.dir_pin.on()
def make_step(self, delay: int = 1000) -> None:
self.step_pin.init(freq=delay, duty_u16=32768)
sleep(1)
self.step_pin.init(freq=500, duty_u16=0)
sleep(1)