feat: stepper logic

This commit is contained in:
xGlc
2026-04-14 21:31:59 +02:00
parent 07d93402b3
commit f94073e1ea
3 changed files with 73 additions and 2 deletions

40
drv8825.py Normal file
View File

@@ -0,0 +1,40 @@
from time import sleep_us
from machine import 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 = step_pin
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.on()
sleep_us(delay)
self.step_pin.off()
sleep_us(delay)
pass

View File

@@ -9,5 +9,9 @@ import display_program
# led program
import led_program
_thread.start_new_thread(led_program.boostrap, ())
_thread.start_new_thread(display_program.display, ())
# motor
import motor
# _thread.start_new_thread(led_program.boostrap, ())
# _thread.start_new_thread(display_program.display, ())
_thread.start_new_thread(motor.motor_run, ())

27
motor.py Normal file
View File

@@ -0,0 +1,27 @@
from time import sleep
from machine import Pin
from drv8825 import DRV8825
def motor_run():
motor = DRV8825(
Pin(21, Pin.OUT), Pin(19, Pin.OUT), Pin(18, Pin.OUT), Pin(5, Pin.OUT)
)
motor.init()
while True:
motor.set_direction(DRV8825.LEFT)
for i in range(0, 1000):
motor.make_step(2000)
sleep(1)
motor.set_direction(DRV8825.RIGHT)
for i in range(0, 1000):
motor.make_step(2000)
sleep(1)