feat: stepper logic
This commit is contained in:
40
drv8825.py
Normal file
40
drv8825.py
Normal 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
|
||||
8
main.py
8
main.py
@@ -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
27
motor.py
Normal 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)
|
||||
Reference in New Issue
Block a user