[Tutor] (no subject)
Dennis Lee Bieber
wlfraed at ix.netcom.com
Tue Apr 5 11:18:12 EDT 2022
On Mon, 4 Apr 2022 15:02:45 -0700, Megan Ani Mirkhanian <mmirkhan at uci.edu>
declaimed the following:
>way to make the two for loops variables so that when I want to make the
>stepper motor go backwards I click on for instance x and enter and when I
>want the stepper motor to go forward I click on for instance y and enter.
>Is there a way to do this?
>
This is rather cloudy... WHAT are "instance x" and "instance y"? Also,
are you using some sort of H-bridge circuit card, or trying to do direct
wire control?
>def forwardStep():
> setStepper(1, 0, 1, 0)
> setStepper(0, 1, 1, 0)
> setStepper(0, 1, 0, 1)
> setStepper(1, 0, 0, 1)
> setStepper(1, 0, 1, 0)
> setStepper(0, 1, 1, 0)
> setStepper(0, 1, 0, 1)
> setStepper(1, 0, 0, 1)
>
EEEEK!
If I understand that, you are performing TWO cycles on each call (the
last four duplicate the first four).
The first thing I'd do is strip out the magic numbers...
FORWARD = [ (1, 0, 1, 0), (0, 1, 1, 0), (0, 1, 0, 1), (1, 0, 0, 1) ]
REVERSE = [ ... ]
... and loop through that (this does just ONE cycle, add extra phases as
needed)...
def stepMotor(sequence):
for phase in sequence:
setStepper(*phase)
You'd then just have some conditional that selects which of FORWARD or
REVERSE gets passed to the stepMotor() invocation.
>def setStepper(in1, in2, in3, in4):
> GPIO.output(IN_1, in1)
> GPIO.output(IN_2, in2)
> GPIO.output(IN_3, in3)
> GPIO.output(IN_4, in4)
> time.sleep(delay)
HOWEVER!
Have you looked at https://github.com/gavinlyonsrepo/RpiMotorLib
(high-level, once set-up there are things like .run() methods) and/or
https://learn.adafruit.com/adafruits-raspberry-pi-lesson-10-stepper-motors/software
(which is a lower-level, basically similar to what you are attempting)
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
More information about the Tutor
mailing list