基于easydriver和rasberry pi的步进电机控制

2024-09-30 20:18:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近开始了我的Rpi项目。
我需要一些关于修改我的代码的帮助或建议。在

我有一个(Pi,+easydriver V4.4,+nema 17步进电机)
使用车身控制模块布局

我需要一个间隔为@的无限嵌套循环

# Do some steps.
for i in range(200):#800 == full rotation
stepper.step()

我希望我的步进器步进200步,然后停止0.1秒,然后再步进200步等(无限循环)

easydriver公司:

^{pr2}$

在步进器.py在

#!/usr/bin/python
# -*- coding: utf-8 -*-

import easydriver as ed


cw = True
ccw = False

"""
Arguments to pass or set up after creating the instance.

Step GPIO pin number.
Delay between step pulses in seconds.
Direction GPIO pin number.
Microstep 1 GPIO pin number.
Microstep 2 GPIO pin number.
Sleep GPIO pin number. #not in use
Enable GPIO pin number.#not in use
Reset GPIO pin number.#not in use
Name as a string.#not in use
"""

# Create an instance of the easydriver class.
# Not using sleep, enable or reset in this example.
stepper = ed.easydriver(8, 0.001, 11, 18, 22)

# Set motor direction to clockwise.
stepper.set_direction(cw)

# Set the motor to run in 1/8 of a step per pulse.
stepper.set_full_step()
# Do some steps.
 for i in range(200):
   stepper.step()

# Clean up (just calls GPIO.cleanup() function.)
stepper.finish()

Tags: thetoinnumbergpiousesteppin
1条回答
网友
1楼 · 发布于 2024-09-30 20:18:52

感觉像个傻瓜。。。在我睡觉的时候有异常! 我是这样创建循环的:

loopinfinity = 1
# Do some steps.(800) full revolution
def step_motor():
  for i in range(120):
    stepper.step()

while loopinfinity > 0:
  try:
     step_motor()
     time.sleep(0.07) #this is in seconds
  except KeyboardInterrupt :
     loopinfinity -=1
     print("stopped")

相关问题 更多 >