教材をhttps://github.com/tjmarkham/python-stepper] [におけるtjmarkham stepper.pyスクリプトからラズベリーPiのCAのnはあなたのボタンの後ろに置くこと:
#CURRENT APPLICATION INFO
#200 steps/rev
#12V, 350mA
#Big Easy driver = 1/16 microstep mode
#Turn a 200 step motor left one full revolution: 3200
from time import sleep
import RPi.GPIO as gpio #https://pypi.python.org/pypi/RPi.GPIO
#import exitHandler #uncomment this and line 58 if using exitHandler
class stepper:
#instantiate stepper
#pins = [stepPin, directionPin, enablePin]
def __init__(self, pins):
#setup pins
self.pins = pins
self.stepPin = self.pins[0]
self.directionPin = self.pins[1]
self.enablePin = self.pins[2]
#use the broadcom layout for the gpio
gpio.setmode(gpio.BCM)
#set gpio pins
gpio.setup(self.stepPin, gpio.OUT)
gpio.setup(self.directionPin, gpio.OUT)
gpio.setup(self.enablePin, gpio.OUT)
#set enable to high (i.e. power is NOT going to the motor)
gpio.output(self.enablePin, True)
print("Stepper initialized (step=" + self.stepPin + ", direction=" + self.directionPin + ", enable=" + self.enablePin + ")")
#clears GPIO settings
def cleanGPIO(self):
gpio.cleanup()
#step the motor
# steps = number of steps to take
# dir = direction stepper will move
# speed = defines the denominator in the waitTime equation: waitTime = 0.000001/speed. As "speed" is increased, the waitTime between steps is lowered
# stayOn = defines whether or not stepper should stay "on" or not. If stepper will need to receive a new step command immediately, this should be set to "True." Otherwise, it should remain at "False."
def step(self, steps, dir, speed=1, stayOn=False):
#set enable to low (i.e. power IS going to the motor)
gpio.output(self.enablePin, False)
#set the output to true for left and false for right
turnLeft = True
if (dir == 'right'):
turnLeft = False;
elif (dir != 'left'):
print("STEPPER ERROR: no direction supplied")
return False
gpio.output(self.directionPin, turnLeft)
stepCounter = 0
waitTime = 0.000001/speed #waitTime controls speed
while stepCounter < steps:
#gracefully exit if ctr-c is pressed
#exitHandler.exitPoint(True) #exitHandler.exitPoint(True, cleanGPIO)
#turning the gpio on and off tells the easy driver to take one step
gpio.output(self.stepPin, True)
gpio.output(self.stepPin, False)
stepCounter += 1
#wait before taking the next step thus controlling rotation speed
sleep(waitTime)
if (stayOn == False):
#set enable to high (i.e. power is NOT going to the motor)
gpio.output(self.enablePin, True)
print("stepperDriver complete (turned " + dir + " " + str(steps) + " steps)")
teststepper.py:
from Stepper import Stepper
#stepper variables
#[stepPin, directionPin, enablePin]
testStepper = Stepper([22, 17, 23])
#test stepper
testStepper.step(3200, "right"); #steps, dir, speed, stayOn
チェック[https://stackoverflow.com/questions/19508450/programmatically-toggle-a-python-pyqt- qpushbutton]またはおそらくtrduamic 2120 +ステッパードライバーでarduinoを使用します。信号低下==モータ停止モード、過負荷など。 [http://www.watterott.com/de/SilentStepStick] – ZF007
ボタンを押すと、ボタンがUSBまたはステッパードライバを介して与えるステップを定義できます。たとえば、button1 =押されたイベントごとに100ステップ。 Button2 = 10ステップ、ボタン3 = 1ステップ...後者の場合、進行を続けるためには、それを継続的に押す必要があります。リリースされた場合... 1つの追加ステップが実行され、停止信号が自動的に送信されます(ステッパードライバまたはお客様のスクリプト内)。 – ZF007
もう一つの非常に役に立つリンクは、[http://zapmaker.org/projects/grbl-controller-3-0/]で、3Dプリンタを制御するarduinoボード用のqt GUIを作成する方法を示しています。ここでは、[http://zapmaker.org/wp-content/uploads/2012/12/mac.png]は左または右に移動するための1ステップサイズを示しています。 – ZF007