MTstepStepper
Event management for Uno, Nano, Mega
For a stepper motor, if the pilot is a driver like A4988, TB6600 or another, that is to say that the command requires a STEP wire (perhaps DIR and en), use the MTstepStepper object. Otherwise, see on the side of MTulnStepper.
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 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 DIR or EN pin
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
micro_pas step_or_micro_step micro_seconds micro_second_per_step absolute_position accelerations_of pin_Step pin_Dir pin_EN
These comments are words that can be added anywhere and which are ignored by the compiler.
Constructor
MTstepStepper(pinStep, pinDir = UNCONNECTED, pinEn = UNCONNECTED, acceleration = 16*200 step_or_micro_step, microsteps = 16 micro_pas, speed = 1.0 RPS, reverse = DEFAULT_SENSE, onStopFunction = NO_ACTION, stepsPerTurn = 200);
- pinStep (int8_t): Arduino pin which controls STEP
- pinDir (int8_t): Arduino pin which controls the sens of rotation (input DIR of the driver)
- pinEn (int8_t): Arduino pin which commands authorizes or not the rotation (input EN of the driver)
- acceleration (int_t): number of micro-steps in acceleration and deceleration
- microsteps (word): Number of micro-steps, by default 16.
- speed (float): rotation speed that can be expressed in various units:
- <digital value> micro_second_per_step → time between two micro-steps, 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, 200 by default
Useful functions
void setSpeed(float speed); void move(int32_t nbSteps); void moveTo(int_t position = 0); void moveAndWait(int32_t nbSteps); void moveToAndWait(int_t position); void stop(void); void wait(void); bool stopped(void); void setPosition(int_t position); int32_t getPosition(void); void setOrigin(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 micro-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)
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 setMicroStepsPerTurn(word microMtepsPerTurn); word getMicroStepsPerTurn(void); float getSpeedMicrosecond(void); float getSpeedRPS(void); float getSpeedRPM(void); 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
setMicroStepsPerTurn: fixes the number of micro-steps per turn
setMicroStepsPerTurn: without parameters fixes the number of micro-steps per turn at 200*16
getMicroStepsPerTurn: return the number of micro-steps per turn
getSpeedMicrosecond: return time between 2 micro-steps in µs
getSpeedRPS: return the speed in RPS
getSpeedRPM: return the speed in RPM
setAcceleration: changes the number of micro-steps for acceleration
Examples