MTulnStepper
Event management for Uno, Nano, Mega
For a stepper motor, if the pilot is a ULN2003 (28BYJ48 stepper) or a unipolar stepper whose 4 coils are commanded directly, use the MTulnStepper object. Otherwise, see on the side of MTstepStepper.
Include to add
#include <MTobjects.h> // See http://arduino.dansetrad.fr/en/MTobjects
I strongly advise to leave the comment, if another person wanted to try the program, they would have a download link directly. This is valid for all the libraries you use.
Useful constants
RPM RPS UNCONNECTED HALF_STEP WHOLE_STEP ONE_PHASE DEFAULT_SENSE REVERSE CONTINUE NO_ACTION NO_ACCELERATION
RPM indicates a r/min constant (rotate per minute)
RPS indicates a r/s constant (rotate per second)
UNCONNECTED for an unconnected A2 and B2 pin
HALF_STEP, WHOLE_STEP, ONE_PHASE to choose the mode
DEFAULT_SENSE, REVERSE to reverse or not the sens
CONTINUE allows continuous rotation for move, moveTo
NO_ACTION default parameter if you do not call for functions at the end of the rotation
Useful comments
step_or_micro_step micro_seconds micro_second_per_step absolute_position accelerations_of pin_A1 pin_B1 pin_A2 pin_B2
These comments are words that can be added anywhere and which are ignored by the compiler.
Constructor
MTulnStepper(pinA1, pinB1, pinA2 = UNCONNECTED, pinB2 = UNCONNECTED, acceleration = 2048 step_or_micro_step, mode = WHOLE_STEP, speed = 0.2 RPS, reverse= DEFAULT_SENSE, onStopFunction= NO_ACTION, stepsPerTurn = 2048);
- pinA1 (int8_t): Arduino pin which controls a coil of a phase. The pins are in the order of a 28BYJ48
- pinB1 (int8_t): Arduino pin which controls a coil from the other phase
- pinA2 (int8_t): Arduino pin which commands the second coil of the first phase for 4-command steppers. UNCONNECTED For steppers that we command with 2 wires
- pinA2 (int8_t): Arduino pin which commands the second coil of the second phase for 4-command steppers. UNCONNECTED For steppers that we command with 2 wires
- acceleration (int_t): number of steps in acceleration and deceleration
- mode (char): operating mode
- WHOLE_STEP → order two phases fed at the same time. Nominal torque (for a 5V engine with a 5V power supply)
- HALF_STEP → double the number of steps, but couple divided by 1.4. We can have the same warm-up
- ONE_PHASE →Control in whole steps one phase at a time. Couple divided by 1.4. Heating divided by 2.
- speed (float): rotation speed that can be expressed in various units:
- <digital value> micro_second_per_step → time between two steps or two half-pas, between 1 and 3600,000 times the time base. Default between 100µs and 1h.
- <digital value> RPS → rotate per second
- <digital value> RPM → rotate per minute
- reverse (boolean): innversion of the senses of rotation, we can also exchange pinA1 and pinA2
- DEFAULT_SENSE → default sens
- REVERSE → reverse all rotations
- onStopFunction: what happens when the stepper reaches its position and initialization
- NO_ACTION → nothing happens
- myFunction → call a function "void myFunction(void) {...}" when stop
- stepsPerTurn (word): number of real steps per turn, 2048 for a 28BYJ48. For the half-step mode leave 2048
Useful functions
void setSpeed(float speed); void move(int32_t nbSteps); void moveAndWait(int32_t nbSteps); void stop(void); void wait(void); bool stopped(void); void setPosition(int_t position); int32_t getPosition(void); void setOrigin(void); void disable(void); void enable(void); int32_t getRest(void); void onStop(void);
setSpeed(<digital value> micro_second_per_step): program a rotation speed
setSpeed(<digital value> RPS): program a rotation speed
setSpeed(<digital value> RPM): program a rotation speed
move: go forward (if nbSteps>0) or backward (if nbSteps <0) of nbSteps steps. By
default the numbers are on 32 bits, but they can be passed in 16 bits, see MTobjects.h. Function is not blocking, we immediately
go out, the stepper will continue its race without anyone taking care of it
move(CONTINUE): advance constantly (you can stop it by stop(); !)
move(-CONTINUE): go back constantly
moveAndWait: advance or decrease but the function awaits the stop
moveAndWait(CONTINUE): advance or decrease (with -CONTINUE) but the function awaits the stop, in this case only by stop();
stop: stop the stepper
wait: blocking function as long as the stepper runs
stopped: return true if the engine is stopped
setPosition: arbitrarily fixes a position
getPosition: return the engine position
setOrigin: fixes the original position here (for example after a machine originating)
disable: disable the driver outputs
enable: réactive les sorties du driver
getRest: reactivate the driver outputs
onStop: function to be overloaded called when the stepper stops and at initialization
Bonus functions
void setReverse(boolean); void setOnStopFunction(onStopFunction); void setStepsPerTurn(word stepsPerTurn); word getStepsPerTurn(void); float getSpeedMicrosecond(void); float getSpeedRPS(void); float getSpeedRPM(void); void setHalfStep(char mode); void setAcceleration(int_t acceleration);
setReverse(REVERSE): allows to reverse the sens of rotation
setReverse(DEFAULT_SENSE:) allows not to reverse the sens of rotation
setOnStopFunction: change the call back function when stopping
setOnStopFunction: without parameters removes the call back function when stopping
setStepsPerTurn: fixes the number of steps per turn
setStepsPerTurn: without parameters fixes the number of steps per turn at 2048
getStepsPerTurn: return the number of steps per turn
getSpeedMicrosecond: return time between 2 steps in µs
getSpeedRPS: return the speed in RPS
getSpeedRPM: return the speed in RPM
setMode(WHOLE_STEP): go to whole step mode, two phases at a time. Use after setStepsPerTurn()
setMode(ONE_PHASE): go to whole step mode, one phase at a time. Use after setStepsPerTurn()
setMode(HALF_STEP): go to half step mode. Use after setStepsPerTurn()
setAcceleration: changes the number of steps for acceleration
Examples