- LICENSE AND COPYRIGHT
RPi::StepperMotor - Control a typical stepper motor with the Raspberry Pi
use warnings; use strict;
my $sm = RPi::StepperMotor->new( pins => [12, 16, 20, 21], speed => 'half', # optional, default delay => 0.01 # optional, default );
$sm->cw(180); # turn motor 180 degrees clockwise $sm->ccw(240); # 240 degrees the other way
$sm->speed('full'); # skip every second step, turning the motor twice as fast $sm->delay(0.5); # set the delay to a half-second in between steps
Control a 28BYJ-48 stepper motor through a ULN2003 driver chip.
This is the only setup I've tested. If I come across any more in the future, I will update this distribution and allow a user to selectively pick which setup they would like to use.
Instantiates and returns a new RPi::StepperMotor object.
pins => $aref
Mandatory, Array Reference: The ULN2003 has four data pins, IN1, IN2, IN3 and IN4. Send in the GPIO pin numbers in the array reference which correlate to the driver pins in the listed order.
speed => 'half'|'full'
Optional, String: By default we run in "half speed" mode. Essentially, in this mode we run through all eight steps. Send in 'full' to double the speed of the motor. We do this by skipping every other step.
delay => Float|Int
Optional, Float or Int: By default, between each step, we delay by
0.01 seconds. Send in a float or integer for the number of seconds to delay each step by. The smaller this number, the faster the motor will turn.
Turns the motor in a clockwise direction by a specified number of degrees.
Mandatory, Integer: The number of degrees to turn the motor in a clockwise direction.
Turns the motor in a counter-clockwise direction by a specified number of degrees.
Mandatory, Integer: The number of degrees to turn the motor in a counter-clockwise direction.
This is the amount of time to delay between each step of the motor. It defaults to
Optional, Float|Int: The number of seconds (or fraction of seconds) to delay between each step of the motor.
The currently set delay time.
The motor can operate in 'half' speed mode (where all eight steps are used) or 'full' speed mode, where every second step is skipped. 'half' speed mode is more accurate, but 'full' speed mode is faster.
Optional, String: Send in 'full' to skip every second step rendering the motor twice as fast. The other option is 'half', which is the default setting.
The currently set speed.
<steveb at cpan.org>
Copyright 2018 Steve Bertrand.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: